MATLAB: Solving for a variable within a loop

loopmach numberrocket nozzlesolvesolve for variable in loop

Situation: Rocket nozzle design.
Code:
% code

gamma=1.4;
R=287; %Gas constant
P0=22313; %Pascals
A_star=0.2; %Throat area in m^2
Ae=1:10;
Me=1;
for i=Ae
AeAs(i)=Ae(i)/A_star;
Ae_As(i)=(1/Me(i))*((2/(gamma+1))*(1+((gamma-1)/2)*(Me(i)^2)))^((gamma+1)/2*(gamma-1))==AeAs(i);
solMe(i)=solve(Ae_As(i),Me(i));
end
I have to vary the area ratio of the exit area of the nozzle (Ae) to the area of the throat (A_star). A_star is fixed, A_e varies. (I have it varying from 1:10). So there are 10 different values for Ae/A_star. Using the equation labeled as "Ae_As(i)", I can solve for Me (exit Mach number). I tried to do this using the solve function which can be seen in the solMe line. When I run this code, I get this error:
% code
Error using solve>processString (line 337)
' 1 ' is not a valid expression or equation.
Error in solve>getEqns (line 267)
eqns = processString(eqns, v, vc);
Error in solve (line 150)
[eqns,vars,options] = getEqns(varargin{:});
Error in Problem_2 (line 14)
solMe(i)=solve(Ae_As(i)==AeAs(i),Me(i));
Is there an easier way to do this? I've tried messing with it for hours and I'm getting nowhere.
Thanks in advance for your help!

Best Answer

There are some errors in your code. I corrected them and got it to run using vpasolve:
syms Me
gamma=1.4;
R=287; %Gas constant
P0=22313; %Pascals
A_star=0.2; %Throat area in m^2
Ae=1:10;
% Me=1;
for i=Ae
AeAs(i)=Ae(i)/A_star;
Ae_As=(1/Me)*((2/(gamma+1))*(1+((gamma-1)/2)*(Me^2)))^((gamma+1)/2*(gamma-1))==AeAs(i);
solMe(i)=vpasolve(Ae_As,Me);
end
I declared ‘Me’ a symbolic variable to solve for rather than a constant, and then solved for it in the last assignment in the loop. The code runs. I leave it to you to determine if it produces the correct results, since the Mach numbers seem low to me. (However, I am not an aerodynamicist, so they could be entirely appropriate.)