Substitute the value of variable in an equation

16 visualizaciones (últimos 30 días)
Bharat Selvam
Bharat Selvam el 12 de Mzo. de 2021
Respondida: Alan Stevens el 12 de Mzo. de 2021
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.

Respuestas (1)

Alan Stevens
Alan Stevens el 12 de Mzo. de 2021
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))

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by