Solving Non-Linear Equations

6 ビュー (過去 30 日間)
Aleksandar Vukojevic
Aleksandar Vukojevic 2014 年 10 月 20 日
コメント済み: Roger Stafford 2014 年 10 月 20 日
I have a problem trying to solve a set of 2 non-linear equations. Here is what I have...
R = (20+0.534*1)/(I^0.88) I = 696/(0.696+R)
I wrote a function for these 2 equations to get them in the form F(x) = 0:
function F = myfun(x) F = [20+0.534*1 - x(1)*(x(2)^0.88); 696-0.696*x(1)-x(1)*x(2)]; end
Then, I wrote:
x0 = [2;3]; options = optimoptions('fsolve','Display','iter'); [x,fval]=fsolve(@myfun,x0,options)
Here is the error:
Error using feval Undefined function 'myfun' for input arguments of type 'double'.
Error in fsolve (line 219) fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
What seems to be the problem here?
Alex
  1 件のコメント
Roger Stafford
Roger Stafford 2014 年 10 月 20 日
Your equations and F are not in agreement. In
20+0.534*1 - x(1)*(x(2)^0.88
x(1) is R and x(2) is I, but in
696-0.696*x(1)-x(1)*x(2)
x(1) is I and x(2) is R.

サインインしてコメントする。

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 10 月 20 日
Make sure that the following function that you wrote:
function F = myfun(x)
F = [20+0.534*1 - x(1)*(x(2)^0.88); 696-0.696*x(1)-x(1)*x(2)];
end
is stored in a file called * myfun.m * and it is in the current folder or within the path.
the best to check if it is working or not is to do this, before calling the fsolve
testF=@myfun
testF([2;3])
You should get some numbers. If you got some errors then myfun.m is not accessible.
Another approach is to define your function as follow:
myfun = @(x) [20+0.534*1 - x(1)*(x(2)^0.88); 696-0.696*x(1)-x(1)*x(2)] ;
You can have this before fsolve and it does not require to be stored in a separate m-file.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by