multiple plots with same variable but different value
3 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 6 Mar 2025
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)
Answers (1)
Vedant Shah
on 6 Mar 2025
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”.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!