multiple plots with same variable but different value

15 ビュー (過去 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 Center および File Exchange2-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