Azzera filtri
Azzera filtri

How to find two unknown variables in explicit function?

4 visualizzazioni (ultimi 30 giorni)
I couldnt solve this matlab code to find unknown variable q and n. Anyone help me
solveeqs3()
Index exceeds the number of array elements. Index must not exceed 1.

Error in solution>eqns (line 55)
n = z(2);

Error in fsolve (line 267)
fuser = feval(funfcn{3},x,varargin{:});

Error in solution>solveeqs3 (line 5)
[result,fval,exit,output]=fsolve(@eqns,guess,options);

Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
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.

Risposta accettata

Torsten
Torsten il 6 Set 2023
Spostato: Torsten il 6 Set 2023
You overwrite z - the 2-element input vector to your function eqns - by setting z=4;
  3 Commenti
M.Rameswari Sudha
M.Rameswari Sudha il 8 Set 2023
Modificato: Torsten il 8 Set 2023
solveeqs3()
Unrecognized function or variable 'sc'.

Error in solution>eqns (line 34)
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);

Error in fsolve (line 267)
fuser = feval(funfcn{3},x,varargin{:});

Error in solution>solveeqs3 (line 5)
[result,fval,exit,output]=fsolve(@eqns,guess,options);

Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
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(Eq)
p=700;
D=1600;
z=4;
m=10;
hr=5;
h1=12;
hb=19.24;
cL=4;
c=20;
ce=15;
Ct=100;
k=0.01;
k1=0.5;
u=0.999;
s=250;
A=150;
g0=15;
g1=20;
theta1=1;
theta2=0.6; w1=0.2; F=50; sigma=5; ts=0.17; pi=80;
q = Eq(1);
n = Eq(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(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 want to find all q and n values using matlab code. Because i didnt get the correct answer. I need to find all values of q and n. if you know the answer, let me know
Torsten
Torsten il 8 Set 2023
Modificato: Torsten il 8 Set 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by