CSE 401/CS 450/MATH 450/ECE 491: Message 241

Date: Tue, 28 Nov 2006 16:31:01
From: S Bond
Subject: Re: Tips for HW 6

Computer Problem 9.6:

For the "perturbed initial condition", try something say
on the order of sqrt(eps).  When you check to see how much
the final value changes, make sure you check the last point
in the solution array (if you set the time interval to be
0 to 100).  This is _not_ the same as the 100th point in the
solution array (unless your array has 100 points).

Computer Problem 10.1 a:

The "shooting method" uses a guess for initial data which
will make the solution interpolate the boundary data.  To
solve this problem

(1) Write an m-file which takes as input the unknown slope
at the left endpoint, u'(0) = v.  Have this m-file function
call an ODE solver (like ODE23 or ODE45) to solve the initial
value problem with this initial data, u(0) = 0 and u'(0) = v.
This m-file function should then return the difference between
the target value at t=1 and the computed value at t=1,

udiff = u(end) - 1;

(2) Pass your m-file function to a root-finding program like
fzero or fsolve, which will try to find the value of the slope for which
this difference is zero.  Once you have this value, you can
run the ODE solver one more time to get a plot of the solution.

Computer Problem 10.1 b:

The "finite difference method" approximates the solution at
regularly spaced nodes by insisting that values at the nodes
solve the finite-difference equations at each node.  To
solve this problem

(1) Write an m-file function which takes as input an array of
solution values at equally spaced nodes.  At each node, compute
the residual of the finite difference equations

r(i) = (u(i+1) - 2*u(i) + u(i-1))/h^2 - f(u(i),t);

where f is the right-hand-side of the BVP.  At the end points,
you can enforce the boundary conditions.  For example, if i=(n+1)
corresponds to the right end point,

r(n+1) = u(n+1) - 1;

Have the m-file return the residual vector as output.  Note that
you can hard-code the boundary values instead, by only using
interior points.  I prefer including them since it allows for
more complicated boundary conditions.

(2) Pass your m-file function to a non-linear systems solver
program like fsolve.  If you don't have fsolve, you can one
that I wrote called pnewt,

http://femto.cs.uiuc.edu/courses/mfiles/

This is a pseudo-newton solver which uses a similar input format
as fsolve.  To plot your result, just plot the u vector.

Computer Problem 10.1 c:

This particular "collocation method" assumes the solution is
a polynomial and approximates the solution by insisting that
the polynomial solves the BVP at a set of equally spaced
nodes.  To solve this problem

(1) Write an m-file function which takes as input an array of
polynomial coefficients.  At a set of equally spaced nodes,
compute the residual of the BVP equations

r(i) = polyval( pdd, t(i) ) - f( polyval( p, t(i) ), t(i) ),

where is the input array of polynomial coefficients, pdd is
an array with the coefficients of the second derivative of
the polynomial, and t(i) are the t-values of some equally
spaced interior point nodes.  You can get the coefficients
of the second derivative using the "polyder" command.  At
the boundary points, you can enforce the boundary conditions.
For example, if i=n corresponds to the right end point,

r(n) = polyval( p, t(n) ) - 1;

Have the m-file return the residual as the output.  Note
that the dimension of the input should be the same as the
output in order to have a system of n-equations with n-unknowns.

(2) Pass your m-file function to a non-linear systems solver
program like fsolve or pnewt.  To plot your result you just
need to plot the polynomial using polyval, just like you did
on the last homework assignment.

HTML 4.01 Updated: Tue, 28 Nov 2006 16:31:01

Powered by Perl Net::NNTP