Problem running my first program

1 回表示 (過去 30 日間)
Florian Spicher
Florian Spicher 2021 年 10 月 17 日
回答済み: Walter Roberson 2021 年 10 月 17 日
I'm trying to use the function fsolve to find the solution of my system of equations.
First, I defined my function NL_Syst_HW4 (see below), which is my system. My problem is when I run fsolve(NL_Syst_HW4, [0,0,0]) it tells me I don't have enough imput argument. Still, my function seems to work since it returns me value when I implement it with (say) [0,0,0].
Thanks for the help!
function [F]=NL_Syst_HW4(x)
F1=92*x(1)+75*x(2)+20*x(3)-60*exp(1);
F2=15*x(1)+16*x(2)+6*x(3)-12*exp(1);
F3=2*x(1)+3*x(2)+6*x(3)+3*(2-2*exp(1));
F=[F1,F2,F3];
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 17 日
fsolve(@NL_Syst_HW4, [0,0,0])
Remember that matlab processes arguments before making the calls. The argument NL_Syst_HW4 has to be processed, and at that point, matlab has no idea that a function handle is expected there. MATLAB does not look and see "oh, fsolve expects a function handle so treat NL_SYST_HW4 as a function handle": matlab processes NL_Syst_HW4 first and passes the result to fsolve.
But what is the result of processing NL_SYST_HW4? Well, that is not a variable so matlab checks to see if it is a function. Having found it to be a function, matlab calls the function with all the provided parameters.. which is no parameters at all. And then the function complained because you did not pass enough parameters.

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by