Introduction to Scientific Computing

Assignment 5

Note: Please do your programming in Matlab and document thoroughly! The code must compile

on one of the lab machines with your instructions.

Instructions

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 [email protected] or come see one of the TAs or the instructor

during office hours well in advance of the due date.