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.

回答(1 个)

Alan Stevens
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))

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by