Description
CS 3200: Introduction to Scientific Computing Assignment 1
1. Write programs to plot the exponential function and the “Hubbard” equation function in the
file hubbard.m on the interval [0,1]. In the Hubbard case use different values of time to show
and describe how the solution evolves in time.
2. Write a simple calling program to use the Matlab routine polyinterp that uses Lagrange
polynomial interpolation ( as described in the text book and given in the Matlab function
polyinterp) based on evenly spaced points to interpolate the Hubbard function on the interval
[0,1]. Use polynomials of degree 28, 36, 44, 52, and 60 and using the L1 L2 and L infinity
norms with 1001 sample points, (as defined in the slides). Comment on how the accuracy
varies in the present case. Change the points used to define the polynomial to the
Chebyshev points of degree N defined on the interval [0,1] denoted by i x where
(1 ) / 2, cos( / ), 0,…, i ii x y y i Ni N =− = = π and comment on the how the accuracy varies in
this case . Use graphs of the errors to illustrate your points and to connect the results back to
the Runge Example used in class.
3. Modify your program that uses the Matlab routine polyinterp that uses Lagrange
polynomial interpolation ( as described in the text book) based on evenly spaced points to
interpolate the GelbTanner function on the interval [-1,1]. Calculate the L2 and Linf (infinity)
error norms and provide a table showing how this error behaves as the polynomial degree is
28, 36, 44,52 and 60 .Again change the points to the Chebyshev points defined on [-1,1] and
comment on the how the accuracy varies in this case . Use graphs of the different solutions
and errors to illustrate your points.
4. Using Matlab’s Cubic Spline Routines . Further modify your codes for both functions to use
the matlab cubic spline routine spline. Compare the performance of the PCHIP interpolant
with the standard spline interpolant both visually and by computing the error norm as
described above what is the accuracy of the two methods and which would you use?
2
For these assignments, we expect both SOURCE CODE(s) and a written REPORT be uploaded
as a zip or tarball file to Canvas.
• Source code for all programs that you write, thoroughly documented.
o Include a README file describing how to compile and run your code.
• Your report should be in PDF format and should stand on its own.
o It should describe the methods used, explain your results and contain figures.
o It should also answer any questions asked above.
o It should cite any sources used for information, including source code and collaborators.
This homework is due on February 2rd 11:59 pm. If you don’t understand these directions, please send
questions to the TAs or come see one of the TAs or the instructor during office hours well in advance
of the due date.
CS 3200: Introduction to Scientific Computing Assignment 2
During lecture we discussed a number of integral quadrature methods. Each method calculates a
set of weight/position pairs {𝑤𝑤𝑖𝑖, 𝑥𝑥𝑖𝑖}, for integrating a curve.
� 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑 ≈ �𝑤𝑤𝑖𝑖𝑓𝑓(𝑥𝑥𝑖𝑖)
𝑁𝑁
𝑖𝑖=1
𝑏𝑏
𝑎𝑎
1. Implement the following Newton-Cotes methods for finding {𝑤𝑤𝑖𝑖, 𝑥𝑥𝑖𝑖} pairs
a. Constant interpolant (composite midpoint rule) for 𝑁𝑁 = 17,33,65,129,257,513
b. Linear interpolant (composite trapezoid rule) for 𝑁𝑁 = 17,33,65,129,257,513
c. Quadratic interpolant (composite Simpson formula) for 𝑁𝑁 = 17,33,65,129,257,513
2. Implement the following Gaussian methods given by the following {𝑥𝑥𝑖𝑖, 𝑤𝑤𝑖𝑖} pairs.
Note: the points are defined on [-1,1] and have to be mapped onto [a,b].
𝑵𝑵 𝒙𝒙𝒊𝒊 𝒘𝒘𝒊𝒊
1 0 2
2 ±1/√3 1
3
0 8/9
±�3/5 5/9
4
±�(3 − 2�6/5)/7 (18 + √30)/36
±�(3 + 2�6/5)/7 (18 − √30)/36
5
0 128/225
±
1
3
�5 − 2�10/7 (322 + 13√70)/900
±
1
3
�5 + 2�10/7 (322 − 13√70)/900
3. Calculate the integral for the function below using all of the methods above.
2
� 1 + sin(𝑥𝑥) ∙ cos �
2𝑥𝑥
3 � ∙ sin(4𝑥𝑥) 𝑑𝑑𝑑𝑑
2𝜋𝜋
0
• Report the results and create a convergence plot for the 3 Newton-Cotes formulas (a) (b)
and (c) above for 𝑁𝑁 = 217,33,65,129,257,513 that shows how quickly the methods go to a
common final value.
o Which of the Newton-Cotes formulas converges fastest? Is that in line with the theoretical
error? Why?
o
• Estimate the error for the Trapezoidal Rule and Simpson’s Rule by estimating the appropriate
derivatives and using the explicit from of the error. Now estimate the errors by using
Richardson Extrapolation . Which error estimates are more accurate?
• Report the results for 𝑁𝑁 = 2, 3, 4, 5 for the Gaussian quadratures given above
o The Gaussian quadratures are high-order functions, yet they don’t do a good job
approximating the integral, why?
o What could be done to make the Gaussian quadratures give better results?
What to turn in
For these assignments, we expect both SOURCE CODE and a written REPORT be uploaded as a zip
or tarball file to Canvas.
• Source code for all programs that you write, thoroughly documented.
o Include a README file describing how to compile and run your code.
• Your report should be in PDF format and should stand on its own.
o It should describe the methods used.
o It should explain your results and contain figures.
o It should also answer any questions asked above.
o It should cite any sources used for information, including source code.
o It should list all of your collaborators.
This homework is due on February 21 by 11:59 pm. If you don’t understand these directions, please
send questions to me or to the TAs or come see one of the TAs or the instructor during office hours
well in advance of the due date.
CS 3200: Introduction to Scientific Computing Assignment 3
1. Complete the LU decomposition of the matrix A where the * entries are the unknowns.
.A =
41 2 100 41 2
44 3 *10 0* *
84 0 **1 00 *
− −
− =
2. Using this decomposition determine the solution of
0
3
16
Ax
=
3. The two matrices B and C are superficially “similar” to matrix A above.
41 2 21 2
4 4 3 and 4 4 3
84 2 84 4
B C
− −
=− =−
are their LU decompositions
similar too?
2
4. This is practical example of a small but real-life-type ill-conditioned problem The flow
of water through two very different materials gives this system of linear equations :
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎡
−𝐻𝐻1
0
0
⋮
0
⋮
0
0
−𝑎𝑎𝑎𝑎𝑟𝑟⎦
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎤
= 1
∆𝑥𝑥2
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎡
−2 1
1 −2 1
1 −2 1
⋱ ⋱ ⋱
1 −(1 + 𝑎𝑎) 𝑎𝑎
⋱ ⋱ ⋱
𝑎𝑎 −2𝑎𝑎 𝑎𝑎
𝑎𝑎 −2𝑎𝑎 𝑎𝑎
𝑎𝑎 −2𝑎𝑎⎦
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎤
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎡ ℎ1
ℎ2
ℎ3
⋮
ℎ𝑖𝑖
⋮
ℎ𝑛𝑛−2
ℎ𝑛𝑛−1
ℎ𝑛𝑛 ⎦
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎤
The coefficient a can be very small indeed a = 1.0e-7 giving an ill-conditioned matrix.
Use ∆𝑥𝑥 = 1 𝑎𝑎𝑎𝑎𝑎𝑎 𝑛𝑛 = 21, 41, 81, 161 .
For values of a = 1.0, 1.0e-1,1.0e-3, 1.0e-5, 1.0e-7 and 1.0e-9, 1.0e-11,
1.0e-13, 1.0e-15 compute the estimated condition number using the matlab
condition number estimator. How does the condition number vary with the
value of a . Explain by using graphs.
If 𝐻𝐻1 = 8 𝑎𝑎𝑎𝑎𝑎𝑎 𝐻𝐻𝑟𝑟 = 4 Solve the system of equations for n= 161, where a =
1.0, a = 1.0e-5 and a = 1.0e-15. Use iterative refinement to check and
improve your answer if possible.
What to turn in
For these assignments, we expect both SOURCE CODE and a written REPORT be
uploaded as a zip or tarball file to Canvas.
• Source code for all programs that you write, thoroughly documented.
o Include a README file describing how to compile and run your code.
• Your report should be in PDF format and should stand on its own.
o It should describe the methods used, explain your results and contain figures.
o It should also answer any questions asked above.
o It should cite any sources used for information, including source code.
o It should list all of your collaborators.
This homework is due on March 11 by 11:59 pm. If you don’t understand these directions,
please send questions to the TAs or come to see one of the TAs or the instructor during
office hours well in advance of the due date.
CS 3200: Introduction to Scientific Computing Assignment 4
1.Write a Newton’s method code to solve the pair of equations given by
3
112 1 2
3
212 2 1
(, ) 1
(, ) 1
fxx x x
f xx x x
= +−
= −+
Use appropriate criteria to measure convergence and to terminate the iteration. Use
starting values of 1 2 x x = = 1.0, 0.1 .Perform a few experiments with different starting values
and count the number of iterations it takes to get to convergence.
2. Repeat the process with the notoriously difficult system of equations given by
1
2 2
112 1 2
( 1) 2
212 2
(, ) 2
(, ) e 2 x
fxx x x
f xx x −
=+−
= −−
As this process is problematic try an alternate approach by using the top equation to
eliminate 2 x from the bottom equation. Find the solution either by using. Newton’s method
for a single equation or by guesswork.
Go back to the full case and use values 1 2 x x = = 1.1, 1.1, 1 2 x x = = 2.0, 0.5 , 1 2 x x = = 3.0, 5.0
as starting values. Does this help. Does the matlab routine fsolve compute a solution in
these cases?
2
3. LORAN LOng RAnge Navigation calculates the position of a boat at sea using signals
from fixed transmitters. From the time differences of the incoming signals the boat obtains
differences of distances to the transmitters. This leads to two equations that represent the
distances such as;
2 2
1 2
112 2 22
2 2
2 1
212 2 22
(, ) 1
186 300 186
( 500) ( 300) (, ) 1
279 500 279
x x fxx
x x f xx
=− − −
− − =− − −
Implement a Newton solver for this system and define the Jacobian matrix.
Using (400,400) as a starting point and run the solution for 25 iterations. This is enough to
get to convergence. Repeat for all starting values from (401, 401) to (600,600) in
increments of 1 (402,402) etc . Which values does the method converge to for which starting
values and how many different solutions are there?
What to turn in
For these assignments, we expect both SOURCE CODE and a written REPORT be
uploaded as a zip or tarball file to Canvas.
• Source code for all programs that you write, thoroughly documented.
o Include a README file describing how to compile and run your code.
• Your report should be in PDF format and should stand on its own.
o It should describe the methods used, explain your results and contain figures.
o It should also answer any questions asked above.
o It should cite any sources used for information, including source code.
o It should list all of your collaborators.
This homework is due on April 4 by 11:59 pm. If you don’t understand these directions,
please send questions to the TAs or come to see one of the TAs or the instructor during
office hours well in advance of the due date.
CS 3200: Introduction to Scientific Computing Assignment 5
1. Solve the coffee cup problem analytically for 5 minutes based upon Newton’s law of cooling:
𝑑𝑑𝑇𝑇𝑐𝑐
𝑑𝑑𝑑𝑑 = −𝑟𝑟(𝑇𝑇𝑐𝑐 − 𝑇𝑇𝑠𝑠)
𝑇𝑇𝑠𝑠 = 19℃, 𝑇𝑇𝑐𝑐 = 84℃, 𝑟𝑟 = 0.025/𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠
By making sure the supplied program runs using Matlab. Write the function Tsexact which is
the analytical solution for use in the supplied matlab code. Use the solution to the in class
activity to help you write this function.
2. Using the supplied program to solve the coffee cup problem using the Forward Euler
Method calculate and compare your results to the analytical answer given by the provided
function.
• Plot the results for all algorithms using several different values for the step size ℎ (ℎ =
30𝑠𝑠, 15𝑠𝑠, 10𝑠𝑠, 5𝑠𝑠, 1𝑠𝑠, 0.5𝑠𝑠, 0.25𝑠𝑠)
• Using these results estimate the order of the error after the first step and at the end of
the integration. Describe how the error changes with changes in ℎ. Use a graph
3. Implement the ODE23 method described in the book Moler in the test program you have
been given . For the standard equation dy/dt = f(t,y) (note y here is Tc above) the method
is given by
• S1 = f(tn,yn)
• S2 = f(tn + h/2, yn+h/2 S1)
• S3 = f(tn + 3h/4, yn+3h/4 S2)
• tn+1 = tn + h
• yn+1 = yn + h/9 ( 2S1 + 3S2 + 4S3)
• S4 = f(tn+1, yn+1)
• Errorn+1 = h/72 ( -5S1 + 6S2 + 8S3 -9 S4)
4. Plot the results for this algorithms using several different values for the step size ℎ (ℎ =
30𝑠𝑠, 15𝑠𝑠, 10𝑠𝑠, 5𝑠𝑠, 1𝑠𝑠, 0.5𝑠𝑠, 0.25𝑠𝑠)
5. Using these results estimate the order of the error after the first step and at the end of the
integration. Compare the actual error on the first step with the predicted error on the first
step.
6. Change the value of r in the problem being solved to r = 0.6. Does the error estimator blow
up in the same way as the solution when the solution becomes unstable?
2
What to turn in
For these assignments, we expect both SOURCE CODES and a written REPORT be uploaded
as a zip or tarball file to Canvas.
• Source code for all programs that you write, thoroughly documented.
o Include a README file describing how to compile and run your code.
• Your report should be in PDF format and should stand on its own.
o It should describe the methods used.
o It should explain your results and contain figures.
o It should also answer any questions asked above.
o It should cite any sources used for information, including source code.
o It should list all of your collaborators.
This homework is due on April 14th by 11:59 pm. If you don’t understand these directions, please
send questions to teach-cs3200@list.eng.utah.edu or come see one of the TAs or the instructor
during office hours well in advance of the due date.