How to get single curve.

3 ビュー (過去 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 Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by