How to solve the range of x axes and obtain y values?
2 次查看(过去 30 天)
显示 更早的评论
I wish to obtain figure as shown below:
here, y axis is r and x-axis is unu_f.
I tried to generate unu_f using a range of "r" values from 0:0.2:4 by solving equation z2. But i am getting curve like,
I have tried the following code but it does not produce the required o/p. Can Anyone please help me generating like in panel (a,b)?
clear; close all; clc;
Vau = 43;
theta_u = 71.8;
gamma = 5/3;
Vsu = 47.45;
tic
unu_f = [];
for r = 0:0.2:4
if r>3.9
r = 3.88;
end
syms Unu
A = r*Vau^2*cosd(theta_u)^2;
B = 2*r*Vsu^2/(r+1-gamma*(r-1));
C = r*Vau^2*sind(theta_u)^2;
D = (2*r - gamma*(r-1))/(r+1 - gamma*(r - 1));
x = Unu^2;
z2 = real(double(solve((x - A)^2*(x - B) - C*x*(D*x - A))));
unu_f = [unu_f;z2'];
end
toc
r2 = 0:0.2:3.9;
r1 = 3.88;
r = [r2 r1];
figure;
subplot(2,2,4)
x = abs(unu_f(:,1));
y = r;
yyaxis left
plot(x,y,'ob')
ylim([0 4]); xlim([0 1200]);
ylabel('r (Shock Strength)','FontWeight','bold','FontSize',10);
xlabel('Shock Speed (km/s)','FontWeight','bold','FontSize',10);
box on; grid on;
set(gca,'XMinorTick','on','YMinorTick','on','FontSize',12,'FontWeight','bold')
set(gca,'LineWidth',2.25,'TickLength',[0.010 0.010],'YColor',[0 0 0]);
0 个评论
采纳的回答
Kiran Felix Robert
2020-10-8
Hi Megha,
To plot specific regions of the curve in different plots (to emphasize certain characteristic features), the following method can be used.
Given that, you have corrected characteristic data, you can use Logical indexing to achieve this.
The Following code gives you an example,
% Sample X vs Y Characteristic [Synthesized Data For Plotting]
x = 1:50;
y = x.^0.5;
% Creating a Specific Case for range 10 to 20
i = x >= 10 & x<20;
y(i) = 20;
% Whole Curve
figure(1);
ax = gca;
plot(x,y); % Plotting Whole
ax.YLim = [0,30];
title('Whole')
% Part 1 Curve
i = x>5 & x < 15; % Selecting Specific Range
B1 = x(i); % Logical Indexing to Select Specific Array
D1 = y(i);
figure(2)
ax = gca;
plot(B1,D1); % Plotting The Specific Array
ax.YLim = [0,30];
title('Part 1')
%Part 2 Curve
i = x>15 & x < 25; % Selecting Specific Range
B2 = x(i); % Logical Indexing to Select Specific Array
D2 = y(i);
f = figure(3);
ax = gca;
p = plot(B2,D2); % Plotting The Specific Array
ax.YLim = [0,30];
title('Part 2')
%Part 3 Curve
i = x>25 ; % Selecting Specific Range
B3 = x(i); % Logical Indexing to Select Specific Array
D3 = y(i);
figure(4);
plot(B3,D3); % Plotting The Specific Array
title('Part 3')
Kiran Felix Robert
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!