multiple plots with same variable but different value

조회 수: 10 (최근 30일)
EIMAN HAZIQ
EIMAN HAZIQ 2021년 4월 27일
댓글: Walter Roberson 2025년 3월 6일
How can I plot a function T(y,t) = erfc((y/2)*sqrt(Pr/t)) with given values for Pr and t as below
Pr = 0.2,0.4,0.6,0.8
t = 1.0, 1.5, 2.0, 2.5
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 3월 6일
You appear to have a function of three variables: y, Pr, and t.
Unless, that is, you are missing out on indicating that those are corresponding values, that t(K) is associated with Pr(K)

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

답변 (1개)

Vedant Shah
Vedant Shah 2025년 3월 6일
To plot multiple graphs of the same variable, which contains different values according to the equation:
T(y,t) = erfc((y/2)*sqrt(Pr/t))
The “hold on” function that is used to plot multiple graphs on the same figure object can be utilized. By looping over the values of Pr and t, it is possible to plot “T” versus y for each pair. Before starting the loop, holdon should be used to ensure all graphs are plotted on the same figure. Once the loop concludes, "hold off” should be applied. Additionally, a legend will be displayed to differentiate between the graphs.
For more information about the “hold” and “legend” functions, please refer to the following documentations:
Below is the code snippet for reference:
figure;
hold on;
% Loop over the pairs of Pr and t
for k = 1:length(Pr_values)
Pr = Pr_values(k);
t = t_values(k);
T = erfc((y / 2) * sqrt(Pr / t));
plot(y, T, 'DisplayName', ['Pr = ', num2str(Pr), ', t = ', num2str(t)]);
end
title('Plots of T(y, t) for Paired Pr and t Values');
xlabel('y');
ylabel('T(y, t)');
grid on;
legend show;
hold off;
This code will produce the desired plots using the specified values of Pr and t.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by