フィルターのクリア

fsolve with functions inside script

7 ビュー (過去 30 日間)
franco otaola
franco otaola 2019 年 9 月 16 日
コメント済み: Matt J 2019 年 9 月 16 日
hello,
i am looking for a way to use fsolve in equations that some of the parameters are defined in the same script.
i am trying to enter A,B in the script, then use fsolve to solve a equation that is for example A+B/x
A=3;
B=2;
x0=1;
fsolve(fun,x0);
function F=fun(A,B,x)
A=A;
B=B;
F=A+B/x
end
and i am having the error that the argument in fsolve initial point is not the right size, i understand that it is because i defined fun as a function of A,B,x so it would expect an array of three values. but if i not define that way how can i put inside the function the desired values that are previously introduced(A and B)?
thanks

回答 (1 件)

Matt J
Matt J 2019 年 9 月 16 日
A=3;
B=2;
x0=1;
fsolve(@(x)fun(A,B,x) ,x0);
function F=fun(A,B,x)
A=A;
B=B;
F=A+B/x
end

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by