Substitute the value of variable in an equation
16 ビュー (過去 30 日間)
古いコメントを表示
In my code, I have an equation which can change depending on the users input and the type of equation (eg. algebraic, trigonometric ). And the eqn. can contain any number of variables. So how to substitute the argument values of the variables into the function from an array?
Eg1 : Let the function be F=3*x^2*y+4*y*x^3+3*a*x.
Let values be x=2,a=3,y=4 which is obtained as input from user and assigned in an array.
And if the function is say F1=4*x*y^2+3*y, the argument value of x and y alone is needed to be substituted.
0 件のコメント
回答 (1 件)
Alan Stevens
2021 年 3 月 12 日
Like this, for example:
F = @(x,y,a) 3*x.^2*y+4*y.*x.^3+3*a*x;
F1 = @(x,y,a) 4*x.*y.^2+3*y;
x = 2; a = 3; y = 4;
disp(F(x,y,a))
disp(F1(x,y,a))
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!