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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by