A simple fsolve problem from a MATLAB beginner
조회 수: 2 (최근 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!
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!