Solve system of non-linear equations with parameter in for loop

2 views (last 30 days)
Hello! I am trying to solve a system of nonlinear equations,but for these equations i have a paramater (D) that takes values from 0 to 0.5, and i try to solve the system in afor loop for each D value.
D=0:0.01:0.5;
for i= 1:length(D)
options=optimset('Display','off');
fsol = fsolve(@solutionsproblem,D(i),options)
X(i) = fsol(1)
end
function F=solutionsproblem(x,D)
mm=0.5;
k=0.1;
ktonos=1;
y=0.3;
a=0.2;
sf=2;
F(1)=D-((mm*x(2)*x(1))/(k+x(2))*(1+(x(3)/ktonos)));
F(2)=-D*x(3)+((a*mm*x(2)*x(1))/(k+x(2))*(1+(x(3)/ktonos)));
F(3)=D*(sf-x(2))-(1/y)*((mm*x(2)*x(1))/(k+x(2))*(1+(x(3)/ktonos)));
end
It keeps telling me the following:
Not enough input arguments.
Error in solutionshit (line 10)
F(1)=D-((mm*x(2)*x(1))/(k+x(2))*(1+(x(3)/ktonos)));
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in ask13pavlou (line 5)
fsol = fsolve(@solutionshit,D(i),options)
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
What am I missing here? Thanks a lot beforehand!

Accepted Answer

Matt J
Matt J on 21 Nov 2018
Edited: Matt J on 21 Nov 2018
It should look something like,
D=0:0.01:0.5;
x0=...
options=optimset('Display','off');
X(i)=nan(1,length(D));
for i= 1:length(D)
fsol = fsolve(@(x) solutionsproblem(x,D(i)), x0, options);
X(i) = fsol(1);
end

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations 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!