Error in fsolve: "Not enough input arguments"

2 views (last 30 days)
Christian E
Christian E on 15 Nov 2015
Commented: Star Strider on 16 Nov 2015
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!

Answers (1)

Star Strider
Star Strider on 15 Nov 2015
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 Comments
Christian E
Christian E on 16 Nov 2015
Update: I seems all variables wasn't specified correctly. It might be running now. Thanks!
Star Strider
Star Strider on 16 Nov 2015
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!