0% found this document useful (0 votes)
1 views

Physics problems

Uploaded by

shivamsharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Physics problems

Uploaded by

shivamsharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Alsaker

Math 350 HW12–Due Fri. Dec. 06


Fall 2024

This assignment is worth 20 points.


Textbook references: A First Course in Numerical Methods, Ascher & Greif

Work must be submitted via Gradescope by 11:59pm on the due date, according to the Homework Submission Instructions
posted on Canvas.

The following problems are required.

1. Recall the 2-stage Runge-Kutta method (RK2) (for a single ODE) given in class:

k1 = hf (tj , yj )
k2 = hf (tj+1 , yj + k1 )
k1 + k2
yj+1 = yj + .
2
(a) Write a MATLAB function which solves y ′ = f (t, y) using the above scheme. For function inputs and
outputs, follow the syntax used for the 4-stage Runge-Kutta (RK4) code we wrote in class (available on
Canvas). Submit your code.
(b) Write a MATLAB script which solves the initial value problem y ′ = −5y, y(0) = 1 by calling functions for
(1) Euler’s method (on Canvas), (2) Your RK2 function from Problem 1, and (3) RK4 (on Canvas). Use time
interval [a, b] = [0, 1] with step-size h = 0.1 for all 3 methods. Then plot the 3 approximations against the
true solution y(t) = e−5t , all on the same axes. Use a discrete marker (e.g. circles, stars, etc.) to designate
the true solution values, and use solid lines in 3 different colors for the three approximations. Add appropriate
axes labels, title, and legend. Submit your code and plot.
(c) Comment on your results. Which method is best? Worst? Does this match the expected results based on
analysis from class?

2. Consider the 2nd-order ODE y ′′ + t2 y ′ + y = t with initial conditions y(0) = 4, y ′ (0) = −8.
(a) Convert the initial value problem into a system of 1st-order ODEs y′ (t) = f (t, y). Write your ODE system
and initial condition in vector notation.
(b) The solution to the ODE system will be a vector y(t). Explain exactly how to get the scalar-valued solution
y(t) to the original initial value problem from the vector y(t).
(c) Write a MATLAB script which solves the initial value problem by calling the functions for (1) Euler’s method
for systems (on Canvas) and (2) RK4 for systems (on Canvas), and (3) ode45. Use time interval [a, b] = [0, 10]
with step-size h = 0.022 for Euler’s Method and RK4, and the default settings for ode45 (this should yield
close to the same number of time steps for all 3 methods). Plot the three approximate solution curves
corresponding to y(t) on the same axes (hint: the dimensions of the solution vector y returned by ode45 will
be N × 2, while the others are 2 × N ). Add appropriate axes labels, title, and legend. Submit your plot.
(d) Comment on your results. Assuming ode45 is close to the true solution, how well do Euler’s and RK4 do?
3. It’s the “ODE to Art” contest! Come up with a 1st-order ODE (or ODE system, if you prefer) that results in
a really interesting plot of solution trajectories (you can use ode45 to solve). Then, use one or more MATLAB
plot commands to prettify the plot. Ideas include making the background of the plot a different color, changing
line color, thickness, style, or markers . . . plotting only certain trajectories, changing the error tolerance in ode45*.
Give your creation a title. Submit your plot and provide the ODE and plotting commands you used. Submissions
will be anonymously shared with the class. This problem is worth 4 points for anyone who follows instructions, but
the WINNER (best plot) will receive an additional 2 bonus points!

* See the ode45example.m code on Canvas for a couple of ideas. You can choose your own colors according to
the RGB 0-1 color model: https://rgbcolorpicker.com/0-1

1
The following problems are strongly recommended but not required. Do not hand these in.

1. Vocabulary: give a definition or explanation for each of the following.


• “stage” as related to RK methods
• nodes and weights of an RK method
• adaptive-step method
2. Given y ′ = −2ty, y(1) = 0, and step-size h = 0.5, find the first two RK2 iterates and the first two RK4 iterates by
hand, using a calculator. Solve the ODE by hand and use this to compute the absolute error of each approximation.
Arrange your results nicely in a table.

You might also like