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 time-step t, an initial value yo, and an initial time t0. If
we are trying to solve the differential equation
dydt=f(t,y),y(t0)=y0
we do this by starting with our approximate solution at t0 and approximating the value at
t1=t0+t using a straight line with slope f(t0,y0). That is, we set
y1=y0+(t)f(t0,y0)
and this should approximate the value of the solution at t0+t. We can iterate this process,
setting
y2=y1+(t)f(t1,y1)
and, in general
yn+1=yn+(t)f(tn,yn)
which should approximate the value of the solution at t0+nt. There is a function
[t,y]=eulerMethod(f,dt,Tf,t0,y0)
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 time-stepping 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 1 to the number of iterations
needed. It is the n in the equations above for Euler's Method.
m is the slope of the tangent line/approximate line that we will use for this step. It is
computed as f(t,y) for the current values of t and y.
The t array stores all of the t values in sequence. The line starting with t(ind+1) will
compute the next value of t based on the previous value t(ind) and the timestep dt.
The y array stores all of the y values in sequence. The line starting with y(ind+1) will
compute the next value of y hosed on the previous value y(ind), the timetep dt, and
the slope n.
Now, consider the initial value problem
dydt=et-t,y(0)=1
which has solution
y(t)=et-t22.
Use the eulerMethod function that you just completed to estimate this solution at Tf=2
using the l value of 0.2. You should also compute the error in this numerical approximation
by taking the absolute value of the difference between the numerical approximation at 2 and
the value of the actual solution y(t) at t=2. You should display the array of solution values
(y) as well as this error. Notes on using this function:
The function gives two outputs, t and y in that order. This means that if you want to
access the y values, you will need to ask for two outputs from the eulerMethod function,
say of the form t,y- eulerMethod (..), and then the output will be stored in y.
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 t=2. This value can then be compared to y(2)
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 t values look like? Check to make sure that
your outputs match these if the results do not look right.
 Euler's Method is a method for approximating solutions to differential equations

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!