Defining the function file for fsolve

5 ビュー (過去 30 日間)
Chandresh Sharma
Chandresh Sharma 2012 年 12 月 23 日
コメント済み: Steven Lord 2020 年 3 月 5 日
function F=nonlinearsolver(x,y) F=[y-x^2-3*x-2; y-2*x-3]; end
This is a function file used to store the system of non linear equation for using with the fsolve. but when ever i called it like this [e,t,exitflag]=fsolve(@nonlinearsolver,[10;10]) it gives errors.
but if i define my function file like this function F=nonlinearsolver(x) F=[x(2)-x(1)^2-3*x(1)-2; x(2)-2*x(1)-3]; end and call the same way as previously it gives right answer. please suggest me the way to rectify the problem associated with the function file or with others.

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 23 日
編集済み: Azzi Abdelmalek 2012 年 12 月 23 日
Your function: replace x by x(1) and y by x(2)
function F=nonlinearsolver(x)
F=[x(2)-x(1)^2-3*x(1)-2; x(2)-2*x(1)-3];
%call your function
sol=fsolve(@nonlinearsolver,[10;10])
  2 件のコメント
farzad
farzad 2020 年 3 月 5 日
@Azzi Abdelmalek : so there should not be a tab for the equation line in the function file ? what about the parameters for example ?
I mean , if I have fixed values to insert in the equation , like the coefficient 3. and if it's a global parameter from the main code, does it create a problem ?
Steven Lord
Steven Lord 2020 年 3 月 5 日
FYI farzad asked this question about indentation in the function files in this question so discussion of that should probably take place in that other question.

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

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by