How to get single curve.

1 次查看(过去 30 天)
MINATI PATRA
MINATI PATRA 2019-8-18
评论: Adam Danz 2019-8-18
H=10;R=5;Pr=1;Q=H-(R/Pr);
xl=0; xr=5; J = 10; dx = (xr-xl) / J; tf = 01; Nt = 100; dt = tf/Nt; mu = dt/(dx)^2;
% Evaluate the initial conditions
x = xl : dx : xr; % generate the grid point
f = 0; %%%I.C
u = zeros(J+1,Nt);
for n = 1:Nt
t = n*dt; % current time
% B.C at left side
gl = t;
% B.C at right side
gr = 0;
if n==1 % first time step
for j=2:J % interior nodes
u(j,n) = (1+dt*Q)*u(j) + (mu/Pr)*(u(j+1)-2*u(j)+u(j-1));
end
u(1,n) = gl;
u(J+1,n) = gr;
else
for j=2:J % interior nodes
u(j,n)= (1+dt*Q)*u(j,n-1)+ (mu/Pr)*(u(j+1,n-1)-2*u(j,n-1)+u(j-1,n-1));
end
u(1,n) = gl; % the left-end point
u(J+1,n) = gr; % the right-end point
end
end
% Plot the results
tt = dt : dt : Nt*dt;
figure(1)
surf(x,tt,u'); % 3-D surface plot
hold on
figure(2)
plot(x,u)
hold on
%%%This code is giving many curves in a single figure but I need only one

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-18
编辑:KALYAN ACHARJYA 2019-8-18
You defined f as scalar
f = 0; %%%I.C
And in the following line, try to acess as a array.
u(j,n) = (1+dt*Q)*f(j) + (mu/Pr)*(f(j+1)-2*f(j)+f(j-1));
%...................^........................^.....^
When you iterate the for loop till J (10) iterartion, how can it get the value of f, as f=0, defined as earlier.
Please note , suppose f=[5 6 4 5 90 200], the
f(1) means 5
f(2) menas 6 ...so on
Alos please ensure that the loop iterartion does not exceded the vector length, those are tring to ecess with the loop.
  1 个评论
MINATI PATRA
MINATI PATRA 2019-8-18
But my f=0 (initial condition u(x,0)=0) for all x
and also gr=0 (Boundary condition for x tends to infinity)
So how to code?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by