Finite Element Method for the Wave Equation in 1D Parameters = 1; = 1; = = 1; = 50; %Length of the domain Total time Wave speed %Number of elements %Time step size %Element size %Number of time steps It = 0.001; x = L/N; t = ceil(T/dt); Initialize variables

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question

solve this equation from matlab by partial differential equation "the finite element method in 1D "

 

please do not provide solution in image format thank you!

1 %Finite Element Method for the Wave Equation in 1D
2
3 %Parameters
4 L = 1;
5 T = 1;
6 c = 1;
7 N = 50;
8 dt
9 dx = L/N;
10 nt ceil(T/dt);
11
20 K
21 for
22
12 %Initialize variables
=
13 x linspace(0, L, N+1);
14 u zeros (N+1, nt);
15 u(:,1)= sin(pi*x/L);
16 u(:,2)= u(:,1)+ dt*zeros (N+1, 1);
17
18 %Assembly of mass and stiffness matrices
19 M
zeros (N+1, N+1);
%Mass matrix
%Stiffness matrix
zeros (N+1, N+1);
i=1:N
23
24 end
0.001;
22238
%Length of the domain
% Total time
%Wave speed
%Number of elements
%Time step size
%Element size
%Number of time steps
25
26 Time integration using the finite element method
27 for n = 2:nt-1
M(i:i+1,i:i+1)=
M(i:i+1,i:i+1) + [dx/6, dx/12; dx/12, dx/6];
K(i:i+1,i:i+1)= K(i:i+1,i:i+1) + [1/dx, -1/dx; -1/dx, 1/dx];
%Spatial grid point
%Solution matrix
%Initial condition
%Seconed time step (forward Euler)
A = M/dt^2 + c^2*K;
b = 2*M* u(:,n)/dt^2 M*u(:,n-1)/dt^2;
u(:,n+1) =A\b;
29
30
31 end
32
33 %Create a meshgrid for 3D plot
34 [X,Y] meshgrid(x, linspace(0, T, nt));
35
36 %Plot the solution in 3D
37 figure;
38 surf (X,Y,u', 'EdgeColor', 'none');
2xlim ( [0 L]);
►ylim ( [0 T]);
xlabel('x');
MATLAB Drive > NA PROJECT.m
42 ylabel('t');
43 zlabel('u');
44 title('Solution of the Wave Equation');
%Cofficient matrix
%Right-hand side
% Solve the linear system
Transcribed Image Text:1 %Finite Element Method for the Wave Equation in 1D 2 3 %Parameters 4 L = 1; 5 T = 1; 6 c = 1; 7 N = 50; 8 dt 9 dx = L/N; 10 nt ceil(T/dt); 11 20 K 21 for 22 12 %Initialize variables = 13 x linspace(0, L, N+1); 14 u zeros (N+1, nt); 15 u(:,1)= sin(pi*x/L); 16 u(:,2)= u(:,1)+ dt*zeros (N+1, 1); 17 18 %Assembly of mass and stiffness matrices 19 M zeros (N+1, N+1); %Mass matrix %Stiffness matrix zeros (N+1, N+1); i=1:N 23 24 end 0.001; 22238 %Length of the domain % Total time %Wave speed %Number of elements %Time step size %Element size %Number of time steps 25 26 Time integration using the finite element method 27 for n = 2:nt-1 M(i:i+1,i:i+1)= M(i:i+1,i:i+1) + [dx/6, dx/12; dx/12, dx/6]; K(i:i+1,i:i+1)= K(i:i+1,i:i+1) + [1/dx, -1/dx; -1/dx, 1/dx]; %Spatial grid point %Solution matrix %Initial condition %Seconed time step (forward Euler) A = M/dt^2 + c^2*K; b = 2*M* u(:,n)/dt^2 M*u(:,n-1)/dt^2; u(:,n+1) =A\b; 29 30 31 end 32 33 %Create a meshgrid for 3D plot 34 [X,Y] meshgrid(x, linspace(0, T, nt)); 35 36 %Plot the solution in 3D 37 figure; 38 surf (X,Y,u', 'EdgeColor', 'none'); 2xlim ( [0 L]); ►ylim ( [0 T]); xlabel('x'); MATLAB Drive > NA PROJECT.m 42 ylabel('t'); 43 zlabel('u'); 44 title('Solution of the Wave Equation'); %Cofficient matrix %Right-hand side % Solve the linear system
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,