Using vpasolve in a for loop ERROR

1 view (last 30 days)
Yoslin Herrera
Yoslin Herrera on 28 Mar 2019
Commented: madhan ravi on 28 Mar 2019
I am trying to solve for the variable M given the values of v2. V2 is a 1x100 and I am looking for the value of M given each one of these V2. I tried implementing a for loop but I ended up with a 1x1 M instead of a 1x100.
syms M
M1=1.5;
gamma=1.4;
alpha=linspace(0,13); %theta max is 13 degrees
%must find M using Prantl-meyer expansion
v1=sqrt((gamma+1)/(gamma-1))*atan(sqrt((.4/2.4)*(M1^2-1)))-atan(sqrt(M1^2-1));
v1=v1*180/pi;
v2=v1+alpha;
for i =length(v2)
v2(i)=v1+alpha(i);
PM=(sqrt((gamma+1)/(gamma-1))*atan(sqrt(((gamma-1)/(gamma+1))*((M^2)-1)))-atan(sqrt((M^2)-1)))*180/pi==v2(i);
solM(i)=vpasolve(PM,M);
end

Answers (1)

Yasasvi Harish Kumar
Yasasvi Harish Kumar on 28 Mar 2019
Hi,
You have an error in your for loop definition and in using vpasolve. I think this should solve it.
syms M
gamma=1.4;
alpha=linspace(0,13); %theta max is 13 degrees
%must find M using Prantl-meyer expansion
v1=sqrt((gamma+1)/(gamma-1))*atan(sqrt((.4/2.4)*(M1^2-1)))-atan(sqrt(M1^2-1));
v1=v1*180/pi;
v2=v1+alpha;
for i =1:length(v2)
v2(i)=v1+alpha(i);
PM=(sqrt((gamma+1)/(gamma-1))*atan(sqrt(((gamma-1)/(gamma+1))*((M^2)-1)))-atan(sqrt((M^2)-1)))*180/pi==v2(i);
solM(i)=vpasolve(PM,M);
end
M = 1.5;
solution = eval(solM);
Regards

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!