A simple fsolve problem from a MATLAB beginner

1 次查看(过去 30 天)
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by