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
Star Strider 2015년 11월 15일

0 개 추천

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
Christian E 2015년 11월 15일
It doesn't. But the error message has now changed to:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in flow_eq (line 8) 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;
Error in @(x)flow_eq(x,rho,c,count,alpha,s_UI,lambda,s_SA,q,k)
Error in fsolve (line 241) fuser = feval(funfcn{3},x,varargin{:});
Error in flow_main (line 4) x = fsolve(fun,x0) Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
Christian E
Christian E 2015년 11월 16일
Update: I seems all variables wasn't specified correctly. It might be running now. Thanks!
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에 대해 자세히 알아보기

질문:

2015년 11월 15일

댓글:

2015년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by