multiple plots with same variable but different value

15 次查看(过去 30 天)
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