Question: 3 MATLAB Project 3 . 1 A Simple Two - Point Boundary Value Problem Write a MATLAB script to divide the interval 0 , 1
MATLAB Project
A Simple TwoPoint Boundary Value Problem
Write a MATLAB script to divide the interval into equal subintervals, and then
implement the finite difference method given by Equation in order to approximate the solution
of the twopoint boundary value problem
at the interior grid points.
The following MATLAB commands generate a sparse tridiagonal representation of the second differ
ence operator on points:
ones;
:spdiags:
Plot your approximate solution to the twopoint boundary value problem in Equation Make sure
the boundary conditions are evident in your plot. You may download the file tpbvpm from the
course web page to do this part of the project.
Find the exact solution to the twopoint boundary value problem in Equation On the same plot,
compare your approximate values at the grid points with the exact solution at the grid points. Your
plot should look similar to Figure Comment on the accuracy of your approximations.
The augmented matrix associated with this system is shown below:
By solving this system, approximate values of the unknown function at the grid points are obtained.
Larger values of produce smaller values of and hence better approximations to the exact values of the
s
Matlab code to use as Basis:
tpbvpm
Solution to the twopoint boundary value problem
ytt y y
n ; Number of interior grid points
a ; Initial time
b ; Final time
ya ; Boundary condition
yb ; Boundary condition
h b an ; Step size
t a:h:b; Time axis
Tridiagonal matrix representation of second difference
e onesn;
A spdiagse e e:nn;
Function ft
f t;
fi hf:end ; Values of f at interior grid points
fi fi ya;
fiend fiend yb;
Approximate solution
yi Afi;
yapp ya; yi; yb;
Exact solution: By integrating ytt twice
and matching the boundary conditions,
ytt t
y t t;
plottyapp,oty
legendApproximate'Exact'
titleSolution to TPBVP: ytt y y
xlabelTime t
ylabelAmplitude yt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
