-
Notifications
You must be signed in to change notification settings - Fork 0
/
WEE.m
34 lines (34 loc) · 968 Bytes
/
WEE.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%===================================
% Shayan Dodge
% MSc in Physics
% M: +98 935 741 67 63
% E: dodgeshayan@gmail.com
% A: Tehran, Iran
%===================================
% The explicit solve of the wave equation (u^2(d^2Q/dx^2)=(d^2Q/dt^2))
% where u is the speed of the wave
%===================================
clc
close all;
%===================================
format bank
u=input('u=');
x_0=input('x_0=');x_n=input('x_n=');
t_0=input('t_0=');t_n=input('t_n=');
deltax=input('h=');r=input('r=');deltat=(sqrt(r).*deltax)./u;
x=[x_0:deltax:x_n];
border_1=input('Q(x=0)=');border_2=input('Q(x=x_n)=');
initial=input('Q(t=0)=');
m=((t_n-t_0)./deltat);n=((x_n-x_0)./deltax);
m=ceil(m)+1;n=ceil(n)+1;
Q=zeros(m,n);
Q(1:m,1)=border_1;Q(1:m,n)=border_2;
Q(1,1:n)=initial;
for j=2:n-1
Q(2,j)=(1-r).*Q(1,j)+(r./2).*[Q(1,j+1)+Q(1,j-1)]
end
for i=2:m-1
for j=2:n-1
Q(i+1,j)=Q(i,j+1)+Q(i,j-1)-Q(i-1,j)
end
end