How to get single curve.

조회 수: 2 (최근 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에서 Filter Banks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by