How to plot graph?

1 次查看(过去 30 天)
Nur Nadhirah Syed Malik
Hi, I really need help. I want to plot graph where the x-axis is the radius (r) and the y-axis is the velocity (u). I want the x-axis the range is from 0 to 1. Can anyone help me, pleaseee
%Parameters to define the governing casson fluid equation and the
%parameters value range
L= 1; % Length of the artery
maxk= 10; % Number of time steps
tmax = 0.1; % Maximum time
delta_t = tmax/maxk; % Time step
n = 10; % Number of space steps
delta_r = L/n; % Radial direction
Beta1 = 0.025; % Casson fluid parameter
A0 = 0.2; % Amplitude of systolic pressure gradient
A1 = 0.4; % Amplitude of diastolic pressure gradient
omega = pi/4;
r= 1;
%Initial conditions of velocity
for i = 1:n+1
u(i,1) = 0;
disp(u(i,1));
end
% Boundary conditions
for j=1:maxk+1
u(1,j) = 0;
u(n,j) = 0;
end
% Implementation of the explicit
for j=1:maxk % Time Loop
for i=2:n % Space Loop
S10 = (u(2,j)-2*u(1,j)+u(2,j))/((delta_r)^2);
S20 = (u(2,j)-u(1,j))/(delta_r);
u(1,j+1) = u(1,j) + delta_t*(A0 + A1*cos(omega*t) + Beta1*((S10) + (1/r)* (S20)));
disp(u(1,j+1))
S1 = (u(i+1,j)-2*u(i,j)+u(i-1,j))/((delta_r)^2);
S2 = (u(i+1,j)-u(i,j))/(delta_r);
u(i,j+1) = u(i,j) + delta_t*(A0 + A1*cos(omega*t) + Beta1*((S1) + (1/r)* (S2)));
disp(u(i,j+1))
S1n = (u(n+1,j)-2*u(n,j)+u(n-1,j))/((delta_r)^2);
S2n = (u(n+1,j)-u(n,j))/(delta_r);
u(n,j+1) = u(n,j) + delta_t*(A0 + A1*cos(omega*t) + Beta1*((S1n) + (1/r)* (S2n)));
disp(u(n,j+1))
end
end
%Graphical representation of the velocity at different selected times
  3 个评论
Nur Nadhirah Syed Malik
That's why, I also dont know how. What do you suggest? Do I need to change anything? Can you help me?
Walter Roberson
Walter Roberson 2021-12-30
I suggest that you are trying to do something that cannot be done, and need to instead change what you are trying to do.
At the moment, you have an r dimension, a time dimension, a spatial dimension, and a result. That is a 3D array of data, which would require a 4 dimensional plot. Such plots are difficult to interpret, but you can try volumeViewer() or slice() or isosurface()

请先登录,再进行评论。

回答(1 个)

Prachi Kulkarni
Prachi Kulkarni 2022-1-11
Hi,
If you want the plots for each timepoint in separate figures, you can use the following code.
r_range = 0:delta_r:1;
for j=1:maxk+1
figure, plot(r_range,u(:,j));
end
If you want the plots for all timepoints in the same plot, you can use the following code.
figure, plot(r_range,u);

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by