taking the output value is input for loops

i have written the code for non linear equations. i got the result.now i have to take output value as input for many times.Like i gave No=3000; and i got the ouput 780 now this ouput i have to give input like this 5 times i have written the code for this but i am getting the error can anyone help me
syms N J
Qo=15000;
R=0.67;
X=13000;
No=3000;
V=25345;
k=1.076;
Kn=0.27
kd=0.04
bs=0.15
Xf=0.49
Df=1.04
Dw=1.3
L=0.004
a=2.24
Y=0.39;
bt=kd+bs
Nstar=N/Kn;
Nmin=Kn/((Y*k/bt)-1);
Lstar=L*(sqrt(k*Xf/Kn*Df))*Df*Dw;
Nstar_min=(1/(Y*k*(bt-1)));
jstar=(J/sqrt(Kn*k*Xf*Df));
for i=1:5
eqn1=Qo*(1+R)*(No-N)-V*(a*J+((X*k*N)/(Kn+N)))==0;
eqn2=sqrt((Lstar^1.76)+5.2*(Nstar-Nstar_min))-(Lstar^0.88)/2.6==jstar^0.88;
soln=vpasolve([eqn1,eqn2],[N,J]);
disp(soln.N)
disp(soln.J)
No(i)=soln.N
end

Réponses (1)

format long g
syms N J
Qo=15000;
R=0.67;
X=13000;
No=3000;
V=25345;
k=1.076;
Kn=0.27;
kd=0.04;
bs=0.15;
Xf=0.49;
Df=1.04;
Dw=1.3;
L=0.004;
a=2.24;
Y=0.39;
bt=kd+bs;
Nstar=N/Kn;
Nmin=Kn/((Y*k/bt)-1);
Lstar=L*(sqrt(k*Xf/Kn*Df))*Df*Dw;
Nstar_min=(1/(Y*k*(bt-1)));
jstar=(J/sqrt(Kn*k*Xf*Df));
for i=1:5
eqn1=Qo*(1+R)*(No(i)-N)-V*(a*J+((X*k*N)/(Kn+N)))==0;
eqn2=sqrt((Lstar^1.76)+5.2*(Nstar-Nstar_min))-(Lstar^0.88)/2.6==jstar^0.88;
soln=vpasolve([eqn1,eqn2],[N,J]);
disp([i, soln.N, soln.J])
No(i+1)=soln.N;
end
No
No = 1×6
3000 0.0724933620740949 -7.68390497970109e-05 -7.82226156737398e-05 -7.82226420515739e-05 -7.82226420520768e-05

4 commentaires

Hello sir,
I have changed the here Df and Dw values to conduct iterations and i am getting the wrong values. But when i am giving single value like i=1,j=1 it is showing correct answer when j=2,i=2 it is showing the error that index exceeds the array of elements .can u help me this??
That is expected. You have
eqn1=Qo*(1+R)*(No(i)-N)-V*((a*J*1000)+((X*k*N)/((Kn*1000)+N)))==0;
which requires that No(i) has already been assigned a value. When you loop over all of the i, then normally you build it up over your iterations, by way of your
No(i+1)=soln.N ;
so the solution to this round becomes the No(i) of the next round. You cannot go directly to the higher i values because the definition of your equations is iterative.
sunitha
sunitha le 2 Mar 2021
how can i modify this code??
What exactly are you hoping the modified code would do for you?
What the current code appears to be doing, is trying to find a steady-state solution. It does not really make sense to say that you want to start that at an iteration after the first.
Ah, I just noticed something:
eqn1=Qo*(1+R)*(No(i)-N)-V*(a*J+((X*k*N)/(Kn+N)))==0;
J is used there
soln=vpasolve([eqn1,eqn2],[N,J]);
and solved for there
No(i+1)=soln.N;
The N solution becomes input for the next iteration.
I notice that there is no feedback of the calculated J value into the next loop. Should there be? If it were fed back in somehow, it would probably have to affect
jstar=(J/sqrt(Kn*k*Xf*Df));
At the moment, I do not see any good reason to feed J back, but it would be good to confirm that you do not want the J value to be fed back. Feeding it back would have odd effects on the equations, I think.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by