I wrote a code for looping an angle value 1 through 100, and set an if condition that when true outputs a total pressure recovery value, my loop is spitting out sym values, what am I doing wrong?

조회 수: 1 (최근 30일)
syms th_1 th_2 th_3 b_1 b_2 b_3 M1 M2 M3 M4 pt1_pt pt2_pt1 pt3_pt2 pt4_pt3 Ptp0 M_1n
%% ignore M1 M_1n, M_2n, M_3n, they are equal due to Oswatisch Principal
M1= 2.6;
gam= 1.4;
%loop iterations for theta and beta1 angles
for th_1= 1:0.1:90
o=double(th_1)
e1= tand(th_1)== 2*cotd(b_1)*(M1^2*sind(b_1)^2-1)/((gam+1)*M1^2-2*(M1^2*sind(b_1)-1));
sol= vpasolve(e1,b_1)
%Upstream of Oblique 1
M_1n= double(M1*sind(b_1)) % M_1n=M_2n=M_3n
%Downstream of Oblique 1
M2= double(M_1n/sind(b_1-th_1));
e2= M1*sind(b_1)==M2*sind(b_2) %%get beta2 first then M2
sol2= vpasolve(e2,b_2)
th_2= double(atand((2*cotd(b_2)^2*(M2^2*sind(b_2)^2-1))/((gam+1)*M2^2-2*(M2^2*sind(b_2)^2-1))))
M3= double(M_1n/(sind(b_2-th_2)))
e3= M2*sind(b_2)==M3*sind(b_3);
sol3= vpasolve(e3,b_3)
th_3= double(atand((2*cotd(b_3)^2*(M3^2*sind(b_3)^2-1))/((gam+1)*M3^2-2*(M3^2*sind(b_3)^2-1))))
%M1, M2, M3,
%Pressure ratios across shock 1
pt1_pt0= double((((gam+1)*M1^2*sind(b_1)^2)/((gam-1)*M1^2*sind(b_1)^2 +2))^(gam/(gam-1))*((gam+1)/(2*gam*M1^2*sind(b_1)^2-(gam-1)))^(1/(gam-1)))
pt1= double((((gam+1)*M2^2*sind(b_2)^2)/((gam-1)*M2^2*sind(b_2)^2 +2))^(gam/(gam-1)));
pt2= double(((gam+1)/(2*gam*M2^2*sind(b_2)^2-(gam-1)))^(1/(gam-1)));
pt2_pt1= double(pt1*pt2)
pt_2= double((((gam+1)*M3^2*sind(b_3)^2)/((gam-1)*M3^2*sind(b_3)^2 +2))^(gam/(gam-1)));
pt_3= double(((gam+1)/(2*gam*M3^2*sind(b_3)^2-(gam-1)))^(1/(gam-1)));
pt3_pt2= double(pt_2*pt_3)
% normal shock, 4th shock
M4= double(sqrt(((gam-1)*M3^2+2))/((2*gam*M3^2-(gam-1))))
pt_4 = double(((gam+1)*M4^2)/((gam-1)*M4^2+2)^(gam/(gam-1)));
pt_3= double(((gam+1)/(2*gam*M4^2-(gam-1)))^(1/(gam-1)));
pt4_pt3 = double(pt_4*pt_3 )%% value of pres. ratio between shock 3 and NS
if ( M4-1.4 < 0.01)
ptp0 = double((pt1_pt0)*(pt2_pt1)*(pt3_pt2)*(pt4_pt3)) %%pressure recovery over inlet
end
end

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 3월 26일
I get an error on this line
M_1n= double(M1*sind(b_1)) % M_1n=M_2n=M_3n
The function double converts a symbolic value to a number. However, in this code you get an error because b_1 has no value assigned to it. It is just a symbolic variable. If you want to turn it into a double, you need to assign a numeric value to b_1. You can use subs for this.
  댓글 수: 2
Esteban Cruz
Esteban Cruz 2020년 3월 26일
otherwise does my code look proper for the function of iterating theta angle value 1? also I'm a bit confused, how should I use the subs function for b_1? thank you.
Cris LaPierre
Cris LaPierre 2020년 3월 27일
What value should b_1 have? This is only the first of many times you're going to have this same error in your code. Any value that is calculated using a variable you declare in in the first line cannot be used with double without first assigning the variable a value first.
As for how to use it, feel free to explore the documentation for subs. Here's an example for b_1
M_1n= M1*sind(b_1) % M_1n=M_2n=M_3n
M_1n = subs(M_1n,b_1,45);
Of course, you could keep it simple by doing this
b_1 = 45;
M_1n= double(M1*sind(b_1)) % M_1n=M_2n=M_3n

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by