Solving for multiple solutions and plotting them

조회 수: 5 (최근 30일)
Benneth Perez
Benneth Perez 2021년 10월 26일
편집: Benneth Perez 2021년 10월 26일
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;

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 26일
편집: Sulaymon Eshkabilov 2021년 10월 26일
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
Benneth Perez
Benneth Perez 2021년 10월 26일
편집: Benneth Perez 2021년 10월 26일
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)

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by