I have the function and the 1D wave equation i.e. du/dt + c.du/dx=0. I have to solve it using Euler's time step series.

8 views (last 30 days)
, u(x,o)= exp(-16*(x-0.5)^2.*sin(125.7*x), Given- c=v=wave velocity=1,
% Initialization
Nx= 480; % x-Grid
dx= 3/480; % Step size
x(:,1)= (0:Nx-1)*dx;
f= 125.7; % Wave number
U(:,1)= -16*(x(:,1)-1/2).^2;
% U(:,1) = exp(-16*(x(:,1)-1/2).^2);
U(:,1)= exp(U(:,1));
U(:,1)= U(:,1).*sin(f*x(:,1));
%U(:,1)= exp(-16*(x(:,1)-1/2).^2)%sin*(f*x(:,1))
%U(:,1)= U(:,1).*sin(f*x(:,1))
mpx= (Nx+1)/2; % Mid point of x-axis
% (Mid point of 1 to 3= 2 here)
T= 10; % Total no. of time step
f= 125.7; % Wave number
dt= 0.000625; % time-step
t(:,1)= (0:T-1)*dt;
v= 1; % wave velocity
c=v*(dt/dx); % CFL condition
s1= floor(T/f);
%%
% Initial condition
x=0:.001:3;
u=@(t)exp(-16*(x-(.75*t+.5)).^2).*sin(125.7*x);
plot(x,u(0))
figure
plot(x,u(2))
%% Euler's method
h= 0.5;
x= 0:h:3; %the range of x
a= 1;
dx= 3/480;
dt= 0.000625;
f= 125.7;
u= zeros(size(x));%allocate the result u
U(:,1) = -16*(x(:,1)-1/2).^2;
% U(:,1) = exp(-16*(x(:,1)-1/2).^2);
U(:,1)= exp(U(:,1));
U(:,1)= U(:,1).*sin(f*x(:,1));
u_prev(i)= U(:,1);
%u(1)= (1); %the initial u value
n= numel(u);%the number of u values
%loop to solve the differential equation
for i=1:n-1
u(i)= exp((-16*(x-.5)).^2).*sin(125.7*x);
u(i)=u_prev(i)-((a*(dtdx)).*(u_prev(i)-u_prev(i-1)));
u(i)=u_prev(i)+(dudt)*h;
end
%%

Answers (0)

Community Treasure Hunt

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

Start Hunting!