フィルターのクリア

A simple fsolve problem from a MATLAB beginner

1 回表示 (過去 30 日間)
Peter J
Peter J 2015 年 1 月 23 日
コメント済み: Peter J 2015 年 1 月 23 日
Hi. I would like to solve a nonlinear equation using fsolve. The variable is denoted as phi. It should have three roots. Below is the mfile that I built.
function out = underwoodroot(phi)
alphaD = 1.00; alphaC = 2.5; alphaB = 6.25; alphaA = 15.625; xAfeed = 0.25; xBfeed = 0.25; xCfeed = 0.25; xDfeed = 0.25;
out = alphaA*xAfeed/(alphaA-phi)+alphaB*xBfeed/(alphaB-phi)+alphaC*xCfeed/(alphaC-phi)+alphaD*xDfeed/(alphaD-phi);
phi1 = fsolve(@underwoodroot,(alphaB+alphaA)/2)
phi2 = fsolve(@underwoodroot,(alphaC+alphaB)/2)
phi3 = fsolve(@underwoodroot,(alphaD+alphaC)/2)
end
However, when I tried to run it, MATLAB returned a "Not enough input arguments" comment. I wonder what happened to my code. As a MATLAB beginner, I would really appreciate any help you have. Thank you so much in advance!

採用された回答

Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 23 日
Define underwoodroot function separately, and call them from another m-file.
In one m-file, write the following code, and save and run:
alphaD = 1.00; alphaC = 2.5; alphaB = 6.25; alphaA = 15.625;
phi1 = fsolve(@underwoodroot,(alphaB+alphaA)/2)
phi2 = fsolve(@underwoodroot,(alphaC+alphaB)/2)
phi3 = fsolve(@underwoodroot,(alphaD+alphaC)/2)
In another m-file, write the underwoodroot function, and save as underwoodroot.m
function out = underwoodroot(phi)
alphaD = 1.00; alphaC = 2.5; alphaB = 6.25; alphaA = 15.625; xAfeed = 0.25; xBfeed = 0.25; xCfeed = 0.25; xDfeed = 0.25;
out = alphaA*xAfeed/(alphaA-phi)+alphaB*xBfeed/(alphaB-phi)+alphaC*xCfeed/(alphaC-phi)+alphaD*xDfeed/(alphaD-phi);
However, if you want to keep them in a single m-file, then use two functions names, like below. Save the m-file as myFunction.m and run that.
function myFunction
alphaD = 1.00; alphaC = 2.5; alphaB = 6.25; alphaA = 15.625;
phi1 = fsolve(@underwoodroot,(alphaB+alphaA)/2)
phi2 = fsolve(@underwoodroot,(alphaC+alphaB)/2)
phi3 = fsolve(@underwoodroot,(alphaD+alphaC)/2)
function out = underwoodroot(phi)
alphaD = 1.00; alphaC = 2.5; alphaB = 6.25; alphaA = 15.625; xAfeed = 0.25; xBfeed = 0.25; xCfeed = 0.25; xDfeed = 0.25;
out = alphaA*xAfeed/(alphaA-phi)+alphaB*xBfeed/(alphaB-phi)+alphaC*xCfeed/(alphaC-phi)+alphaD*xDfeed/(alphaD-phi);
  1 件のコメント
Peter J
Peter J 2015 年 1 月 23 日
Thank you so much for your help. That solves the problem.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by