Error in fsolve: "Not enough input arguments"
이전 댓글 표시
Hi all,
I hope you might be able to help me out. I get an error message saying "Not enough input arguments" in my code using fsolve below.
First I run some codes giving me the parameter called rho, c, count, alpha, s_UI, lambda, s_SA, q, and k.
Then I run the following:
fun = @(x) flow_eq;
x0 = zeros(2*c*count);
x = fsolve(fun,x0)
Where flow_eq is:
function [F] = flow_eq(x, rho, c, count, alpha, s_UI, lambda, s_SA, q, k)
F(1)=(1-rho)*x(c*count+1)-(1-alpha*s_UI)*lambda*x(2);%(1-rho)*e_SA(c*count-1)-(1-alpha*s_UI)*lambda*u_UI;
F(2)=sum(x(1:2*c*count))-1;
for i=1:c*count-1
F(i+2)=alpha*s_SA(q(i))*x(c*count+1+q(i))-x(2+i);
F(c*count+1+i)=rho*x(2+k(i))-alpha*s_SA(i)*x(c*count+1+i);
end
end
Any ideas? - Thanks!
답변 (1개)
Star Strider
2015년 11월 15일
Your ‘fun’ is not collecting the rest of the input arguments to ‘flow_eq’.
See if changing it to this helps:
fun = @(x) flow_eq(x, rho, c, count, alpha, s_UI, lambda, s_SA, q, k);
Be sure all the other variables are present in your workspace before you define ‘fun’.
댓글 수: 3
Christian E
2015년 11월 15일
Christian E
2015년 11월 16일
Star Strider
2015년 11월 16일
My pleasure!
(Away for a few minutes here.)
See if completely vectorising this line (I’ve done it here) will solve the problem:
F(1)=(1-rho).*x(c*count+1)-(1-alpha.*s_UI).*lambda.*x(2); %(1-rho)*e_SA(c*count-1)-(1-alpha*s_UI)*lambda*u_UI;
See Array vs. Matrix Operations for details. Beyond that I have no idea, because I don’t know the dimensions of your variables. To be assigned to a scalar array element such as ‘F(1)’, the operation must produce a scalar value.
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!