필터 지우기
필터 지우기

pde matlab code for wave equation

조회 수: 16 (최근 30일)
nandine
nandine 2018년 4월 26일
댓글: Torsten 2018년 4월 26일
this is my code so far, however it seems matlab is not going through my iteration and simply plotting the initial condition. can someone please check to see where i am going wrong?
% setup and parameters
Nx = 50; % number of mesh points
dx = 10/Nx; % spactial mesh
Tend = 1;% solve from t=0..tmax
c = 0.2*ones(Nx-1,1); % vector of ones , size Nx-1
dt = 0.95*dx/max(c);% time step
t = 0:dt:Tend; % time mesh
R = round(Tend/dt); % number of timesteps
x = linspace(0,10,Nx-1);% create spatial coordinates vector for plots
% set up differentiation matrices
e = ones(Nx-1,1); % vector of ones of same size x
Dx =(spdiags([-e e],[-1 1],Nx-1,Nx-1)); % 1st order matrix
Dxx = (spdiags([e -2*e e], [-1 1], Nx-1,Nx-1)); % 2nd order matrix
% initialization and initial conditions, u = zero at boundaries
u = exp(-100 * (x-5).^2);
data = u; % store data
for n = 2:R-1 % iteratre, step in time
for j= 2:Nx-1
u(j,n+1) = u(j,n) - 0.5*dt/dx * c.*(Dx*u(j,n)) + 0.5*(dt/dx)^2 * c.^2*(Dxx*u(j,n)) ...
+ 0.125*(dt/dx)^2 * c.*(Dx*c).*(Dx*u(j,n));
end
end
(plot(x,data,'o - r'));xlabel('x'); ylabel('u'); title('Solution at t=1')
  댓글 수: 3
nandine
nandine 2018년 4월 26일
R is my time step,and I need my scheme to start at t=0 to t=1. In in increments of dt
Torsten
Torsten 2018년 4월 26일
You use for n=2:R-1, thus for n=2:0, thus the loop is never executed.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sigurd Askeland
Sigurd Askeland 2018년 4월 26일
It seems you are plotting data in stead of u. When you set data = u before the for loop, any subsequent changes to u are not reflected in data. data is a copy of u, and does not point to the same memory address.

카테고리

Help CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by