How to get single curve.

2 visualizaciones (últimos 30 días)
MINATI PATRA
MINATI PATRA el 18 de Ag. de 2019
Comentada: Adam Danz el 18 de Ag. de 2019
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

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 18 de Ag. de 2019
Editada: KALYAN ACHARJYA el 18 de Ag. de 2019
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 comentario
MINATI PATRA
MINATI PATRA el 18 de Ag. de 2019
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Filter Banks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by