Question: 3 MATLAB Project 3 . 1 A Simple Two - Point Boundary Value Problem Write a MATLAB script to divide the interval 0 , 1

3 MATLAB Project
3.1 A Simple Two-Point Boundary Value Problem
Write a MATLAB script to divide the interval 0,1 into 21(n+1) equal subintervals, and then
implement the finite difference method given by Equation (10) in order to approximate the solution
of the two-point boundary value problem
y''(t)=125t,y(0)=y(1)=0
at the 20(n) interior grid points.
The following MATLAB commands generate a sparse tridiagonal representation of the second differ-
ence operator on n points:
e=ones(n,1);
{:A=spdiags([e,-2**e,e]],-1:1,n,n)
Plot your approximate solution to the two-point boundary value problem in Equation (11). Make sure
the boundary conditions are evident in your plot. You may download the file tpbvp1.m from the
course web page to do this part of the project.
Find the exact solution to the two-point boundary value problem in Equation (11). 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 2. Comment on the accuracy of your approximations.
The augmented matrix associated with this system is shown below:
[2-10dots000-h2f1-12-1dots000-h2f20-12dots000-h2f3vdotsvdotsvdotsddotsvdotsvdotsvdotsvdots000dots2-10-h2fn-2000dots-12-1-h2fn-1000dots0-12-h2fn].
By solving this system, approximate values of the unknown function y at the grid points ti are obtained.
Larger values of n produce smaller values of h and hence better approximations to the exact values of the
yi's.
Matlab code to use as Basis:
% tpbvp1.m
% Solution to the two-point boundary value problem
% y''(t)=125t, y(0)= y(1)=0
n =20; % Number of interior grid points
a =0; % Initial time
b =1; % Final time
ya =0; % Boundary condition
yb =0; % Boundary condition
h =(b - a)/(n +1); % Step size
t =[a:h:b]'; % Time axis
% Tridiagonal matrix representation of second difference
e = ones(n,1);
A = spdiags([-e 2*e -e],-1:1,n,n);
% Function f(t)
f =125*t;
fi =-h^2*f(2:end -1); % Values of f at interior grid points
fi(1)= fi(1)+ ya;
fi(end)= fi(end)+ yb;
% Approximate solution
yi = A\fi;
yapp =[ya; yi; yb];
% Exact solution: By integrating y''(t)=125t twice
% and matching the boundary conditions,
% y(t)=(125/6)(t^3- t)
y =(125/6)*(t.^3- t);
plot(t,yapp,'o',t,y)
legend('Approximate','Exact')
title('Solution to TPBVP: y"(t)=125t, y(0)= y(1)=0')
xlabel('Time, t')
ylabel('Amplitude, y(t)')
3 MATLAB Project 3 . 1 A Simple Two - Point

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!