multiple plots with same variable but different value

15 visualizaciones (últimos 30 días)
EIMAN HAZIQ
EIMAN HAZIQ el 27 de Abr. de 2021
Comentada: Walter Roberson el 6 de Mzo. de 2025
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 comentario
Walter Roberson
Walter Roberson el 6 de Mzo. de 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)

Iniciar sesión para comentar.

Respuestas (1)

Vedant Shah
Vedant Shah el 6 de Mzo. de 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.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by