Rho = 997;
g = 9.8;
Le =115.25 ;
Ae =214.4 ;
Ac =51.5 ;
Li =172;
Ai =84.13;
Di = (Ae/Ac)^2 - 1;
S = Ac;
beta2 = 14.3*(%pi/180);
w=92.3*(2*%pi)/60;
R=4;
U2 = w*R;
Head=114;
alfa = 1.3;
zt2 = 0.29;
ztT=34.47;
Qm=740;
n=20;
Xv=logspace(0,3,n)*1e-3;
Cv=logspace(0,4,n)*1e-6;
Sol=zeros(2,n);
%%%%
Cav = 0;
for h=1:n
X=-Xv(h);
for i=1:n
Cc=Cv(i);
Eq=(Rho*Qm*(zt2-Di)/Ae^2)-((y^2)*Rho*X*(Li/Ai))-(Rho*Qm*(ztT/Ai^2))+Cc*(2*Rho^2*(y^2)*((cot(beta2))/S)*(((cot(beta2))/S)*Qm-U2)*(Le/Ae)+Rho^2*(Li/Ai)*(y^2)*Qm*((Di-zt2)/Ae^2)-(y^2)*(Rho^2)*(Le/Ae)*(ztT/Ai^2)*Qm)+Cav*(2*(Rho^2)*(y^2)*((cot(beta2))/S)*(((cot(beta2))/S)*Qm-U2)*(Le/Ae)+(Rho^2)*(Li/Ai)*(y^2)*Qm*((Di-zt2)/Ae^2)-(y^2)*(Rho^2)*(Le/Ae)*(ztT/Ai^2)*Qm); %%EQUAÇÃO CARACTERÍSTICA
Sol(:,i)=double(vpasolve(Eq,y)); % SOLUÇÃO DA EQ. CARACTERÍSTICA
Wr(h,i)= Eq(Sol(2,i));
I need to apply the result i get from vpasolve back in Eq so I can determinate if Wr is positive or negative and plot a graphic with it.
I am trying to plot a graphic with the solution, however in the last line I always get "Index exceeds array bounds"

5 Comments

Is there any guarantee that the result of a vpasolve of an equation will be a valid index into the Eq variable? It seems unlikely, but I don't use vpasolve so I wouldn't really know.
What are the sizes of Eq, and Sol, and the value of i when it errors?
upload all the missing datas
The size of Eq is 1x1, Sol is 2x20 and i errors with value 1. I am no sure about guarantees, I am using vpasolve because it was used in a similar code, but is was a complex cubic equation.
I can not upload the data here, sorry.
You are using the result of this complex cubic equation to index into a scalar though. This makes no sense! I don't know what you are attempting to do with
Eq( Sol(2,i) )
but since Eq is a scalar then unless Sol(2,i) evaluates to 1 every time (in which case it is pointless) then it will error.

Sign in to comment.

 Accepted Answer

madhan ravi
madhan ravi on 10 Oct 2018
Edited: madhan ravi on 10 Oct 2018
EDITED
syms y
Rho = 997;
g = 9.8;
Le =115.25 ;
Ae =214.4 ;
Ac =51.5 ;
Li =172;
Ai =84.13;
Di = (Ae/Ac)^2 - 1;
S = Ac;
beta2 = 14.3*(pi/180);
w=92.3*(2*pi)/60;
R=4;
U2 = w*R;
Head=114;
alfa = 1.3;
zt2 = 0.29;
ztT=34.47;
Qm=740;
n=20;
Xv=logspace(0,3,n)*1e-3;
Cv=logspace(0,4,n)*1e-6;
Sol={zeros(1,n)}
%%%%
Cav = 0;
for h=1:n
X=-Xv(h);
for i=1:n
Cc=Cv(i);
Eq=(Rho*Qm*(zt2-Di)/Ae^2)-((y^2)*Rho*X*(Li/Ai))-(Rho*Qm*(ztT/Ai^2))+Cc*(2*Rho^2*(y^2)*((cot(beta2))/S)*(((cot(beta2))/S)*Qm-U2)*(Le/Ae)+Rho^2*(Li/Ai)*(y^2)*Qm*((Di-zt2)/Ae^2)-(y^2)*(Rho^2)*(Le/Ae)*(ztT/Ai^2)*Qm)+Cav*(2*(Rho^2)*(y^2)*((cot(beta2))/S)*(((cot(beta2))/S)*Qm-U2)*(Le/Ae)+(Rho^2)*(Li/Ai)*(y^2)*Qm*((Di-zt2)/Ae^2)-(y^2)*(Rho^2)*(Le/Ae)*(ztT/Ai^2)*Qm); %%EQUAÇÃO CARACTERÍSTICA
Sol{i}=double(vpasolve(Eq,y)); % SOLUÇÃO DA EQ.
end
end
celldisp(Sol) %this will display all the solutions you need :)
Sol=cell2mat(Sol) %to use for further calculations
Wr = vpa(subs({Eq},{Sol}))

2 Comments

How do I apply the result back in Eq? I tried using this code, but shows errors.
"Array indices must be positive integers or logical values
Error in sym/subsref (859)
R_tilde = builtin('subsref', L_tilde. Idx);
Error in Rotina
Wr(h,i) = Eq(Sol);
see edited now

Sign in to comment.

More Answers (1)

Jan
Jan on 10 Oct 2018
If Eq is a scalar, a 1x1 array, than the only working value of Sol(2,i) is 1. Otherwise Eq(Sol(2,i)) must fail, of course.
We cannot run the code due to the missing data, and cannot guess, what the code should do due to the lack of comments and explanations. It is not clear which variables are symbolic and which are numerical. Maybe you have redefined cot as an array?

1 Comment

The only symbolic is y. I uploaded the data if it helps.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!