 
 How do i plot this solutions?
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hello, 
I want to plot the theta2 values on the x and presures (P2_ALL) on a plot. It seems my pressures are in symbolic form so Im using fplot to plot. When I do this it gives me an error. Does anyone know how to fix this?
clc; clearvars 
format short g 
M1 = 3 ; 
P1 = 1 ; 
theta2 = 1:1:30 ; 
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}=vpa(P2) ; 
end
fplot(theta2,P2_ALL)
0 Commenti
Risposte (1)
  Abhaya
 il 26 Set 2024
        Hello Benneth, 
The issue you are experiencing arises because the second argument of the MATLAB 'fplot' function is a cell array. Typically, the MATLAB 'fplot' function is designed to plot expressions or functions. In this case, the variable 'P2_ALL' contains a cell array of cells. To address this, here are two potential solutions to plot variable 'P2_ALL' against variable 'theta2'. 
1. Convert the Cell Array to a Vector:  You can add the following lines of code to your existing script in order to create a vector from the variable 'P2_ALL'.
vecP2 = [P2_ALL{1,:}]; 
plot(theta2, vecP2); 
2. Change 'P2_ALL' from a Cell Array to a Vector: Instead of making variable ‘P2_ALL’ a cell array, you can make it a vector. Here is the updated code: 
clc; clearvars  
format short g  
M1 = 3 ;  
P1 = 1 ;  
theta2 = 1:1:30 ;  
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 vector of sym 
    P2_ALL(ii)=vpa(P2) ;  
end 
plot(theta2,P2_ALL); 
With following either of the approach, you can plot the variable ‘P2_ALL’ against ‘theta2’. The result can be shown as the figure attached below. 
 
 For more information on MATLAB ‘fplot’ function, please refer to the documentation given below. 
Hope this resolves the query.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

