Solving for multiple solutions and plotting them

2 views (last 30 days)
Hello,
By choosing one value to theta2 I'm able to solve for one solution of beta and then use it to calculate P2.
What Id like to do is solve for multiple solutions of beta and then use those to find the correstpoing P2 (pressure 2).I tried making theta2 an array but it does not work.
Once thats complete I want to plot all angles and the correspoinding pressure 2(P2).
The code works if i just set theta 2 to some interger but when i want to make it an array to solve for many Beta which i need to solve for P2s i get an error. HELP
clc
clear all
format short g
M1 = 3;
P1 = 1;
theta2 = 1:1:20;
gamma = 1.4;
phi = 4.8;
syms beta2
tantheta2 = tand(theta2);
x = 2*cotd(beta2)*((M1^2*((sind(beta2))^2)-1));
y = M1^2*(gamma+cosd(2*beta2))+2;
eqn2 = x/y;
b0=1;
result2 = vpasolve(tantheta2 == eqn2, beta2,b0);
beta2 = vpa(result2);
Mn1 = M1*sind(beta2);% Eqn 4.7 from Anderson's
p2p1 = 1+((2*gamma)/(gamma+1))*(Mn1^2-1);% Eqn 4.9 from Anderson's
Mn2sq = (Mn1^2+(2/(gamma-1)))/((2*gamma/(gamma-1))*Mn1^2-1);% Eqn 4.10 from Anderson's
Mn2 = sqrt(Mn2sq);
M2 = Mn2/sind(beta2-theta2);
P2 = p2p1*P1;

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 26 Oct 2021
Edited: Sulaymon Eshkabilov on 26 Oct 2021
Here is the corrected code:
clc; clearvars
format short g
M1 = 3;
P1 = 1;
theta2 = 1:1:20;
gamma = 1.4;
phi = 4.8;
syms beta2
tantheta2 = tand(theta2);
x = 2*cotd(beta2)*((M1^2*((sind(beta2)).^2)-1));
y = M1^2*(gamma+cosd(2*beta2))+2;
eqn2 = x/y;
b0=1;
for ii=1:numel(theta2)
T = tantheta2(ii);
clearvars result2
syms beta2
result2 = vpasolve(T== eqn2, beta2,b0);
beta2 = vpa(result2);
Mn1 = M1*sind(beta2); % Eqn 4.7 from Anderson's
p2p1 = 1+((2*gamma)/(gamma+1))*(Mn1^2-1); % Eqn 4.9 from Anderson's
Mn2sq= (Mn1^2+(2/(gamma-1)))/((2*gamma/(gamma-1))*Mn1^2-1);% Eqn 4.10 from Anderson's
Mn2 = sqrt(Mn2sq);
M2 = Mn2/sind(beta2-theta2(ii));
P2 = p2p1*P1;
P2_ALL{ii}=P2;
end
  1 Comment
Benneth Perez
Benneth Perez on 26 Oct 2021
Edited: Benneth Perez on 26 Oct 2021
This seems to work how ever all the solutions are symbolics and I want to be able to plot them?
I'm guessing if I wanted to make a plot of changing theta angles vs p2 i would do something likes this? However, this is not working and I'm guessing its bc P2_All are symbolic solutions?
plot(theta2,P2_ALL)

Sign in to comment.

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!