How to perform iterations for lopp
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have imported N and V values from excel, only these two variables are varying. Now i have to write the code for Qo=1000,i have to find N & J values then Qo=2500 find N& J values upto 10000.For N & V i gave 23 inputs .so for Qo=1000 i have to get 23 different N & J values, but here iam getting the values for only one Qo value
Qo=1000:1500:10000;
nX =length(No);
q = length(Qo);
q1 = q*nX;
Solutions= cell(q1, 2);
for i=1:q
for S=1:nX
X =((bt*Qo(i)*(1+R)*Xo)+(Y*1000*a*V(S)*J*bs))/(bt*((Qo(i)*(1+R))-((V(S)*Y*k*N)/((Kn*1000)+N))+(V(S)*kd)));
eqn1=(Qo(i)*(1+R)*(No(S)-N)-(V(S)*((a*J*1000)+((X*k*N)/((Kn*1000)+N)))))==0;
eqn2=(sqrt((Lstar^1.76)+(5.2*(Nstar-Nstar_min)))-(Lstar^0.88))/2.6==jstar^0.88;
Solutions{S} = vpasolve([eqn1,eqn2],[N,J]);
end
2 Kommentare
Walter Roberson
am 10 Feb. 2021
you have a double loop but your output is only indexed by one of the two variables
Antworten (5)
Walter Roberson
am 11 Feb. 2021
Bearbeitet: Walter Roberson
am 11 Feb. 2021
syms N J
Qo=1000:1500:10000;
nX =length(No);
q = length(Qo);
Solutions= cell(nX, q);
for i=1:q
for S=1:nX
X =((bt*Qo(i)*(1+R)*Xo)+(Y*1000*a*V(S)*J*bs))/(bt*((Qo(i)*(1+R))-((V(S)*Y*k*N)/((Kn*1000)+N))+(V(S)*kd)));
eqn1=(Qo(i)*(1+R)*(No(S)-N)-(V(S)*((a*J*1000)+((X*k*N)/((Kn*1000)+N)))))==0;
eqn2=(sqrt((Lstar^1.76)+(5.2*(Nstar-Nstar_min)))-(Lstar^0.88))/2.6==jstar^0.88;
Solutions{S, i} = vpasolve([eqn1,eqn2],[N,J]);
end
end
sunitha
am 17 Feb. 2021
1 Kommentar
Walter Roberson
am 17 Feb. 2021
J1(i,j) = double(soln);
However, notice that
eqn1=(sqrt((Lstar^1.76)+(5.2*(Nstar-Nstar_min)))-(Lstar^0.88))/2.6==jstar^0.88;
does not use Ne or N1 or No or Ans (the variables you assign to in the loops) so you are going to be calculating exactly the same thing every iteration.
Your original code with two equations in N and J had the same problem. Also, there was no obvious connection between the variables such as Lstar and the variables N or J, so the fragments posted before give the impression that the equation is independent of the variable, J, being solved for.
sunitha
am 17 Feb. 2021
Bearbeitet: sunitha
am 17 Feb. 2021
5 Kommentare
Walter Roberson
am 17 Feb. 2021
Ans(j,1)=No(j);
That tells us No is a vector. It was a vector before in previous posts but you changed your code and did not show assigning to it, so we could not assume that it is still a vector in your current code.
B=bt*Qo*(1+R)*((k*Se(j,i))*(Y*(No-Se(j,i))+ Xo)+(((Kn*1000)+Se(i,j))*((a*J1(j,i)*1000)-(kd*(No(i,j)-Se(i,j))))));
The first access to No is not indexed so it uses the whole vector and so B will be a vector of results.
The second reference to No is indexed with two variables, implying that No is two dimensional instead of a vector, which is likely a problem compared to using it as a vector for Ans.
V(j,i)=(sqrt((B.^2)-(4*A*C))-B)/(2*A);
B is a vector or possibly an array so the right hand side is vector or array but you are storing it in a scalar location.
sunitha
am 11 Mär. 2021
1 Kommentar
Walter Roberson
am 11 Mär. 2021
eqn1=(jstar*Lstar)+((0.5*jstar^2)+(jstar((1+((jstar/3.4)^1.19)^-0.61))))/tanh(jstar/Nstar_min)==Nstar;
^^^^^^
In MATLAB, NAME followed by ( can mean one of several things:
- NAME is a variable that has been assigned a function handle, and the function is to be invoked passing in whatever list is inside the (); or
- NAME is not a variable, but is the name of a function that is "visible" in the scope, and the function is to be invoked passing in whatever list is inside the (); or
- NAME is not a variable, but is the name of a method for the dominent object class encountered inside the () and the class method is to be called for the object class; or
- NAME is not a variable, but is the name of a function that the user expects to be in scope, but is not, and the call is in error
- NAME is a variable and what follows inside the () is a list of indices that are comprised of positive integers, or logical values, or character vectors (but not string objects), which are to act to index the variable; or
- NAME is a variable and what follows in the () includes things that are not positive integers or logical values or character vectors, and the call is an invalid indexing attempt
Your jstor is not the name of a function or a variable designating a function handle: it is the name of a scalar expression, so jstor can only be followed immediately by () for indexing. However, (1+((jstar/3.4)^1.19)^-0.61) is not a positive integer, so the indexing attempt fails.
There are absolutely no circumstances in MATLAB in which NAME followed immediately by () is ever treated as implied multiplication. Never. If you intend multiplication you must always use .* (element-by-element multiplication) or * (algebraic matrix multiplication -- inner product)
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!