0% found this document useful (0 votes)
18 views3 pages

Experiment 10

The document describes solving a 1D wave equation with given initial and boundary conditions numerically. It involves: 1. Deriving the general solution as a sum of sines with coefficients An and Bn found by integrating the initial conditions. 2. Writing a script that calculates An and Bn, defines a function for the solution u, and plots the solution over space and time. 3. Evaluating the numerical solution at specific space and time points.

Uploaded by

Abhishek Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Experiment 10

The document describes solving a 1D wave equation with given initial and boundary conditions numerically. It involves: 1. Deriving the general solution as a sum of sines with coefficients An and Bn found by integrating the initial conditions. 2. Writing a script that calculates An and Bn, defines a function for the solution u, and plots the solution over space and time. 3. Evaluating the numerical solution at specific space and time points.

Uploaded by

Abhishek Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment-10

OBJECTIVE:
Write a script file to solve and plot the solution of
one-dimensional wave equation with given initial-
boundary conditions:
 2u  2u x x u
c2
 2 ; u (0, t )  0, u ( L, t )  0; u ( x, 0)  (1  ), ( x, 0)  x
x 2
t L L t

(i) Take c=1, L=1 and n(no. of terms in sol)=20


(ii) plot for x=0:0.05:1, t=0:0.025:0.5
(iii) display solution for x=0.25, t=0.075
Theory: Physically it represents vibrations of a stretched string
• Solution :
• 1-Dim Wave Equation: 
n x  n ct n ct 
u u
2 2 u ( x, t )   sin A
 n cos  Bn sin 
c2
 2 , 0  x  L, 0  t   n 1 L  L L 
x 2
t

Boundary conditions(Always same): where


n x
L
u (0, t )  0, 2
An   f ( x)sin dx
u ( L, t )  0 L0 L

Initial conditions(f(x) and g(x) and


n x
L
2
can be any functions of x):
u ( x, 0)  f ( x),
Bn  
n c 0
g ( x ) sin
L
dx
u
( x, 0)  g ( x)
t Note: We write algorithm such that
1. First we construct An or A(i)
In our problem: 2. Next Bn or B(i)
c=1, L=1, f(x)=(x/L)(1-x/L), 3. Finally solution u
g(x)=x
Algorithm
5.//To calculate u
1.Write clc, clear and clf commands
*Define a function with name ‘u’, input ‘x’ and “t” and
2.Enter the values of c ,L, n
output ‘uu’
3. // To find An that is A(i)
*Define a function with name ‘f’, input ‘x’ and initialize uu=0
output as ‘w1’. for j=1 to n
w1=(x/L)(1-x/L) uu=uu+sin(j pi x/L)(A(j) cos(j pi c t/L)+ B(j) sin(j pi c
endfunction t/L))
* for i=1 to n
end
Define a function with name ‘f1’, input ‘x’ and
output as ‘w2’. Endfunction
w2=f(x)sin(i pi x/L) 6. // To plot 3d and 2d plot
endfunction x=0:0.05:1, t=0:0.025: 0.5
A(i)=(2/L)integrate(‘f1(x)’ , ‘x’, 0, L)
u1=feval(x,t,u)
end
plot3d(x,t,u1, ‘x@t@u(x,t)’)
4. // To find Bn that is B(i) scf(1)
*Define a function with name ‘g’, input ‘x’ and plot( x’, u1(:,1), ”*g”, x’, u1(:,3), ”xr”, x’, u1(:,6), ”-b”,
output as ‘w3’. x’, u1(:,9), ”+o”)
w3=x
7.// numerical output
endfunction
* for i=1 to n u1=feval(0.25, 0.075,u)
Define a function with name ‘g1’, input ‘x’ and disply u1
output as ‘w4’.
w4=g(x)sin(i pi x/L)
endfunction
B(i)=(2/(i pi c))integrate(‘g1(x)’ , ‘x’, 0, L)
End

You might also like