• Remix
  • Share
  • New Entry

on 15 Oct 2021
  • 1
  • 8
  • 0
  • 0
  • 268
x=0:.1:4.95;
y=x;
dx=.1;
U=zeros(50,50);
UM=U;
UP=U;
C=.25; % Courant Number
dt=C*dx/2; % Time step
t=0;
while t<5
U(:,[1,end])=0;
U([1,end],:)=0;
t=t+dt;
UM=U;
U=UP;
U(25,25)=.5*sin(2*t*pi);
for ii=2:49
for jj=2:49
UP(ii,jj)=2*U(ii,jj)-UM(ii,jj)+(C^2)*(U(ii+1,jj)+U(ii,jj+1)-4*U(ii,jj)+U(ii-1,jj)+U(ii,jj-1));
end
end
surf(x,y,U');
%pause(dt) % To simulate the code remove "%"
end
Remix Tree