How to access symbolic expression based on arithmetic operators MATLAB

故事扮演 提交于 2019-12-04 21:17:53

symbolic variables are defined with syms command.

MATLAB code:

syms x y z C v1 v2 v3 v4;
v1 = x/y;
v2 = v1+C;
v3 = log(v2);
v4 = v3*x;
.......

or if u just need expr then,

syms x y z C expr;
expr = x + (x/z)*log(C + x/y);   

And then to explore those variables: e.g (x=1,y=2,z=3,C=4 in expr)

subs(expr,{x,y,z,C},{1,2,3,4});  

This will give:

expr = 1 + (1/3)*log(9/2);

But I would recommend you use the anonymous function instead if you don't want to use MATLAB inbuilt differentiation or Integration or some other symbolic functions. They are much faster and easy to work with.

expr = @(x,y,z,C) x + (x/z)*log(C + x/y);
expr(1,2,3,4)

This will give result: 1.501359...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!