Plotting for various values of the same parameter on the same plot

조회 수: 11 (최근 30일)
Ke Le
Ke Le 2021년 8월 28일
댓글: Star Strider 2021년 8월 30일
Asking here on how to plot "Y1(2,:)" for multiple "S" values on the same figure?. Consider values such as "S=0.1, 0.5, 1.1, 1.5" etc.
dYdX = @(X,Y) [Y(2); Y(3); S*Y(2).^2+Y(1).*Y(3)];
res = @(ya,yb) [ya(1)-1; ya(2); yb(2)];
SolYinit = bvpinit(linspace(0,5,50),[0; 0.2; 0.4]);
Fsol = bvp4c(dYdX, res, SolYinit);
X1 = Fsol.x;
Y1 = Fsol.y;
figure (1)
plot(X1, Y1(2,:), 'LineWidth', 2);
hold on
  댓글 수: 2
Ive J
Ive J 2021년 8월 28일
hold on, have you tried hold on?
Ke Le
Ke Le 2021년 8월 28일
@Ive J Yes, it doesn't show it there, however, I've tried it there. Even with "hold on", I am looking for help on plotting for various "S" values. Any help will be appreciated.

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

채택된 답변

Star Strider
Star Strider 2021년 8월 29일
Set ‘S’ as a vector, add ‘S’ as an additional parameter to the ‘dYdX’ function, then iterate through the values of ‘S’.
Try this —
Sv = [0.1, 0.5, 1.1, 1.5];
dYdX = @(X,Y,S) [Y(2); Y(3); S*Y(2).^2+Y(1).*Y(3)];
res = @(ya,yb) [ya(1)-1; ya(2); yb(2)];
SolYinit = bvpinit(linspace(0,5,50),[0; 0.2; 0.4]);
for k = 1:numel(Sv)
S = Sv(k);
Fsol = bvp4c(@(X,Y)dYdX(X,Y,S), res, SolYinit);
X1{k} = Fsol.x;
Y1{k} = Fsol.y;
end
figure (1)
Nrsp = numel(Sv);
for k = 1:Nrsp
subplot(Nrsp,1,k)
plot(X1{k}, Y1{k}(2,:), 'LineWidth', 2)
grid
title(sprintf('S = %.1f',Sv(k)))
end
I opted for the subplots because the scales vary so significantly on the solutions that the details in the solution for ‘S(1)’ gets lost if they are all plotted on the same axes.
.
  댓글 수: 4
Star Strider
Star Strider 2021년 8월 30일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (1개)

the cyclist
the cyclist 2021년 8월 28일
% Some data
x = 1:10;
% Create the figure window, use the hold command
% to prevent overwriting of axes
figure
hold on
% Plot line with different slope parameters
for s = 1:3
plot(x,s*x)
end
  댓글 수: 1
Ke Le
Ke Le 2021년 8월 28일
@the cyclist How should we treat the above system for S values such as "-0.1, 0.5, 1.1, 1.5"?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by