A simple fsolve problem from a MATLAB beginner

1 Ansicht (letzte 30 Tage)
Peter J
Peter J am 23 Jan. 2015
Kommentiert: Peter J am 23 Jan. 2015
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!

Akzeptierte Antwort

Shoaibur Rahman
Shoaibur Rahman am 23 Jan. 2015
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 Kommentar
Peter J
Peter J am 23 Jan. 2015
Thank you so much for your help. That solves the problem.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by