How to find two unknown variables in explicit function?
3 views (last 30 days)
Show older comments
I couldnt solve this matlab code to find unknown variable q and n. Anyone help me
solveeqs3()
function solveeqs3()
guess=[0.05 200];
options = optimoptions('fsolve','Display','iter');
[result,fval,exit,output]=fsolve(@eqns,guess,options);
result
fval
eqns(guess)
output
end
function fcns=eqns(z)
%pr=7;
p=700;
%p=2500;
%pmin=700;
%pmax=1200;
D=1600;
z=4;
m=10;
hr=5;
h1=12;
%h2=11;
%h3=13;
hb=19.24;
cL=4;
c=20;
%c0=2;
%c1=3;
%c2=2;
ce=15;
Ct=100;
k=0.01;
k1=0.5;
%alpha=0.1;
%beta=0.99;
u=0.999;
s=250;
A=150;
g0=15;
g1=20;
theta1=1;
theta2=0.6;
%w0=0.3;
w1=0.2;
F=50;
sigma=5;
ts=0.17;
pi=80;
%zeta=0.5;
%zeta1=300;
%zeta2=1/300;
%sp=15;
sc=0.5;
q = z(1);
n = z(2);
%fcns(1)=-((A+F+n*Ct)*(D/n*q^2))+(hb*(1/2+((k1*sigma)/(2*p*sqrt(ts+(q/p))))))-((D*pi/n*q^2)*((sigma/2)*(sqrt(ts+(q/p))*(sqrt(1+k1^2)-k1))))+((D*pi/n*q)*(( sigma/2*p*sqrt(ts+(q/p))*(sqrt(1+k1^2)-k1))))+(n*sc)-(z*m*D/n* q^2)+((hr+cL*k)*(D*n/2*m*p))+(h1*(1-(((2*u-1)*D)/(2*p*u)))*n)-(h1*n/2)-(s*D/n*q^2)-(c*D*g0/n*q^2)-(D*ce*n*theta1*g0/n*q^2)+w1*(1-(((2*u-1)*D)/(2*p*u))*n-(n/2))*ce*theta2;
fcns(1)= -((A+F+n*Ct)*(D/n*q^2))+(hb*(1/2+((k1*sigma)/(2*p*sqrt(ts+(q/p))))))-((D*pi/n*q^2)*((sigma/2)*(sqrt(ts+(q/p))*(sqrt(1+k1^2)-k1))))+((D*pi/n*q)*((sigma/2*p*sqrt(ts+(q/p))*(sqrt(1+k1^2)-k1))))+(n*sc)-(z*m*D/n*q^2)+((hr+cL*k)*(D*n/2*m*p))+(h1*(1-(((2*u-1)*D)/(2*p*u)))*n)-(h1*n/2)-(s*D/n*q^2)-(c*D*g0/n*q^2)-(D*ce*n*theta1*g0/n*q^2)+(w1*(1-(((2*u-1)*D)/(2*p*u))*n-(n/2))*ce*theta2);
fcns(2)= -((A+F)*(D/q*n^2))-((D*pi/q*n^2)*((sigma/2)*(sqrt(ts+(q/p))*(sqrt(1+k1^2)-k1)))+(q*sc)-(z*m*D/q*n^2)+((hr+cL*k)*(D*q/2*m*p))+(h1*(1-(((2*u-1)*D)/(2*p*u)))*q)-(h1*q/2)-(s*D/q*n^2)-(c*D*g0/q*n^2)+D*ce*theta1*g1)+(w1*(1-(((2*u-1)*D)/(2*p*u))*q-(q/2))*ce*theta2);
%fcns(2)=-((A+F)*(D/q*n^2))-((D*pi/q*n^2)*((sigma/2)*(sqrt(ts+(q/p))*(sqrt(1+k1^2)-k1)))+(q*sc)-(z*m*D/q*n^2)+((hr+cL*k)*(D*q/2*m*p))+(h1*(1-(((2*u-1)*D)/(2*p*u)))*q)-(h1*q/2)-(s*D/q*n^2)-(c*D*g0/q*n^2)+D*ce*theta1*g1)+(w1*(1-(((2*u-1)*D)/(2*p*u))*q-(q/2))*ce*theta2);
end
I got this message while I was running this code.
Failure in initial objective function evaluation. FSOLVE cannot continue.
0 Comments
Accepted Answer
Torsten
on 6 Sep 2023
Moved: Torsten
on 6 Sep 2023
You overwrite z - the 2-element input vector to your function eqns - by setting z=4;
3 Comments
Torsten
on 8 Sep 2023
Edited: Torsten
on 8 Sep 2023
If you didn't get the "correct" answer, I assume that you at least know the approximate answer for q and n. Try the answer you expect as the "guess" vector and see whether fmincon reproduces your guess. If not, I would suspect there is something wrong with your equations.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!