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.

5 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
%% 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);

Answers (0)


Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by