MATLAB Answers

How can I shade the area between a curve and a vertical line?

2 ビュー (過去 30 日間)
shahin sharafi
shahin sharafi 2021 年 7 月 18 日
コメント済み: Star Strider 2021 年 7 月 18 日
I am going to shade the area between the right side of vertical line and the curve as bellow. Could someone help me? I have attached the code as well.
m=60;L=1;J=60;g=9.81;Time_Delay=0.2;beta2=411.67;
%%
syms w
% W=[0.0001:0.1:18*pi];
W=[0.00001:0.1:3*pi];
% time=[0:0.1:1];
%%
omega=w;
tau=Time_Delay;
Kp1=(J*omega^2 + L*g*m)*cos(omega*tau)/(J*beta2);
Kd1=(J*omega^2 + L*g*m)*sin(omega*tau)/(J*beta2*omega);
%%
figure('DefaultAxesFontSize',10,'DefaultAxesFontName','Times')
D_Curve_PD_KP1=eval(subs(Kp1,w,W));
D_Curve_PD_KD1=eval(subs(Kd1,w,W));
%%
plot(D_Curve_PD_KP1,D_Curve_PD_KD1,'color',[1 0 0.75],'LineWidth', 2)
xlabel ('Kp','FontSize',11, 'FontName', 'Times')
ylabel ('Kd','FontSize',11, 'FontName', 'Times')
axis([0,0.05,0,0.025]);
title('TT', 'FontName', 'Times','FontSize',11)
grid on
hold on
%% Line
plot([0.02385 0.02383],[0 0.025],'color',[0 0 0.75],'LineWidth', 2)
  1 件のコメント
shahin sharafi
shahin sharafi 2021 年 7 月 18 日
The picture has been attached

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2021 年 7 月 18 日
Try this —
m=60;L=1;J=60;g=9.81;Time_Delay=0.2;beta2=411.67;
%%
% syms w
% W=[0.0001:0.1:18*pi];
% W=[0.00001:1E-4:3*pi];
W = linspace(1E-5, 3*pi, 1000);
% time=[0:0.1:1];
%%
omega=W;
tau=Time_Delay;
Kp1 = @(omega) (J*omega.^2 + L*g*m).*cos(omega*tau)/(J*beta2);
Kd1 = @(omega) (J*omega.^2 + L*g*m).*sin(omega*tau)./(J*beta2*omega);
%%
figure('DefaultAxesFontSize',10,'DefaultAxesFontName','Times')
% D_Curve_PD_KP1=eval(subs(Kp1,w,W));
% D_Curve_PD_KD1=eval(subs(Kd1,w,W));
D_Curve_PD_KP1 = Kp1(omega);
D_Curve_PD_KD1 = Kd1(omega);
%%
figure
mv = D_Curve_PD_KP1 > 0.02383;
patch(D_Curve_PD_KP1(mv), D_Curve_PD_KD1(mv), 'g', 'EdgeColor','none')
hold on
plot(D_Curve_PD_KP1,D_Curve_PD_KD1,'color',[1 0 0.75],'LineWidth', 2)
xlabel ('Kp','FontSize',11, 'FontName', 'Times')
ylabel ('Kd','FontSize',11, 'FontName', 'Times')
axis([0,0.05,0,0.025]);
title('TT', 'FontName', 'Times','FontSize',11)
grid on
%% Line
plot([0.02385 0.02383],[0 0.025],'color',[0 0 0.75],'LineWidth', 2)
hold off
The patch call can be a bit of a challenge, since it also involves creating the logical vector ‘mv’ (mask vector). Beyond that, I eliminated the Symbolic Math Toolbox invocation, recoding ‘Kd1’ and ‘Kp1’ as anonymous functions. (See the documentation section on Anonymous Functions if you are not familiar with them.) I rearranged the plot calls so that the patch will plot first. The curve and line plots then plot over it.
.
  2 件のコメント
Star Strider
Star Strider 2021 年 7 月 18 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (1 件)

Alan Stevens
Alan Stevens 2021 年 7 月 18 日
編集済み: Alan Stevens 2021 年 7 月 18 日
Try
help fill
or
help patch
Although they refer to polygons, you could easily represent your curve as a multi-segment polygon.

Community Treasure Hunt

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

Start Hunting!

Translated by