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 个)

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 个评论

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.
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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by