Question: Although we can perform many modeling tasks in Excel, a full - fledged scientific computing programming language like MATLAB can do much more and do
Although we can perform many modeling tasks in Excel, a fullfledged scientific computing
programming language like MATLAB can do much more and do so more efficiently. In this
problem, we will learn how to write simple MATLAB programs to solve an ODE numerically.
a In the last module, we learned how to use Euler method to solve an ODE numerically:
;
Write a MATLAB function that implements Euler method. The definition should be:
feuler
where fun is a userdefined function that should take in two arguments, and in that
order, and return The program will simulate the ODE from to with
time step and return the simulated data points as two vectors tt and yY
consisting of the s and the corresponding s respectively.
b The Euler method we learned is properly called the "forward Euler" method since it
assumes that the slope between and can be approximated by the slope
evaluated at The formula is:
Another variant of Euler method is the "backward Euler" method, which uses the slope
evaluated at the point instead, resulting in the formula:
Since we actually do not know yet, we cannot evaluate right away and
plug it into the formula. Instead, we need to solve this implicit formula to calculate
In MATLAB, you can do this with the fzero function see the MATLAB tutorial video on
"Root Finding"
Write a MATLAB function that implements "backward Euler" method. The definition
should be:
tt yy beulerfun y tf h
c Yet another method for solving ODEs is the "midpoint method," which uses the slope at
the midpoint between and :
Similar to the backward Euler method, you will need to use fzero to find at each
step. Write a MATLAB function that implements this method. The definition should be:
tt yy meulerfun y tf h
d Apply each of the methods from Parts ac to Question c Write a MATLAB program
to solve the ODE of Question c for using each method one by one, and plot the
solutions from each method, together with the analytical solution in the same plot. For
simplicity, calculate directly from its analytical solution and only use the numerical
methods to solve for Your function definition should be:
Fin,
e For a parameter setting of your choice, use your program to compare and discuss the
error behaviors of the methods. Show several plots of the solutions at different step
sizes Make sure you try a large enough so that you can see the differences more
clearly.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
