Question: Euler's Method is a method for approximating solutions to differential equations numerically. The process is as follows. Pick a time - step t , an
Euler's Method is a method for approximating solutions to differential equations numerically.
The process is as follows. Pick a timestep an initial value yo and an initial time If
we are trying to solve the differential equation
we do this by starting with our approximate solution at and approximating the value at
using a straight line with slope That is we set
and this should approximate the value of the solution at We can iterate this process,
setting
and, in general
which should approximate the value of the solution at There is a function
eulerMethod
written near the bottom of the MATLAB format file. There are a few lines missing from
the code that are annotated with comments. Fill in those lines with the code that nexds to
be there for the method to work properly. You are filling in the timestepping part of the
process, which was described above, Keep in mind bow MATLAB arrays work. The lines are
as follows
ind is the current index of the array. This will step from to the number of iterations
needed. It is the in the equations above for Euler's Method.
is the slope of the tangent lineapproximate line that we will use for this step. It is
computed as for the current values of and
The array stores all of the values in sequence. The line starting with will
compute the next value of based on the previous value ind and the timestep dt
The array stores all of the values in sequence. The line starting with ind will
compute the next value of hosed on the previous value ind the timetep and
the slope
Now, consider the initial value problem
which has solution
Use the eulerMethod function that you just completed to estimate this solution at
using the value of You should also compute the error in this numerical approximation
by taking the absolute value of the difference between the numerical approximation at and
the value of the actual solution at You should display the array of solution values
y as well as this error. Notes on using this function:
The function gives two outputs, and in that order. This means that if you want to
access the values, you will need to ask for two outputs from the eulerMethod function,
say of the form eulerMethod and then the output will be stored in
To get the last value of an array, you can use y end In the case of Enler's method,
this will give the approximate value at This value can then be compared to
when written as a function in Matlab. Make sure you take the absolute value of the
difference, as the error should be positive.
Think about the output that you get from this method. How many values should there
be in each array? What should the list of values look like? Check to make sure that
your outputs match these if the results do not look right.
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
