A simple fsolve problem from a MATLAB beginner
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
Shoaibur Rahman
le 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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!