Substitute the value of variable in an equation

조회 수: 16 (최근 30일)
Bharat Selvam
Bharat Selvam 2021년 3월 12일
답변: Alan Stevens 2021년 3월 12일
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