Euler Methods:
Numerical Solution of an IVP:Presume we wish to numerically solve the initial value problem
y? = f (t, y), y(a) = y0,
On an period of time [a, b].
By a numerical solution we should mean an approximation of the solution at a finite number of points that is:
(t0, y0), (t1, y1), (t2, y2), . . . ,(tn, yn),
Where t0 = a and tn= b The first of these points is precisely the initial value. If we acquire n steps as above and the steps are evenly spaced then the time change in every step is
h = (b − a)/ n
and the times ti are given simply by ti= a + ih. This leaves the mainly important part of finding a numerical solution determining y1, y2, . . . ,yn in a manner that is as consistent as possible with.
To do this first write the discrepancy equation in the indexed notation:
y?i ≈ f (ti, yi),
And will then put back the derivative y? by a difference. There are several ways we might carry this out and in the next section we study the simplest.
The Euler Method:
The mainly straight forward approach is to replace y? i by its forward difference approximation.
This gives:
(yi+1– yi)/h= f (ti, yi).
Rearranging this gives us a method to obtain yi+1 from yiknown as Euler’s method:
yi+1 = yi+ hf (ti, yi).
With this formula we are able to start from (t0, y0) and compute all the subsequent approximations (ti, yi).
This is extremely easy to implement as you can see from the following program (which can be downloaded from the class web site)
function [T , Y] = myeuler(f,tspan,y0,n)% function [T , Y] = myeuler(f,tspan,y0,n)% Solves dy/dt = f(t,y) with initial condition y(a) = y0% on the interval [a,b] using n steps of Euler s method.% Inputs: f -- a function f(t,y) that returns a column vector of the same% length as y% tspan -- a vector [a,b] with the start and end times% y0 -- a column vector of the initial values, y(a) = y0% n -- number of steps to use% Outputs: T -- a n+1 column vector containing the times% Y -- a (n+1) by d matrix where d is the length of y% Y(t,i) gives the ith component of y at time t% parse starting and ending pointsa = tspan(1);b = tspan(2);h = (b-a)/n; % step sizet = a; y = y0; % t and y are the current variablesT = a; Y = y0’; % T and Y will record all stepsfor i = 1:ny = y + h*f(t,y);t = a + i*h;T = [T; t];Y = [Y; y’];End
To utilization this program we need a function such as the vector function for the pendulum
> f = inline(’[y(2);-.1*y(2)-sin(y(1)) + sin(t)]’,’t’,’y’)
Then type:
> [T Y] = myeuler(f,[0 20],[1;-1.5],5);
Here [0 20] is the time span you desire to consider, [1;-1.5] is the first value of the vector y and 5 is the number of steps. The output T contains times as well as Y contains values of the vector as the times. Try
>size(T)>size(Y)
Since the initial coordinate of the vector is the angle we merely plot its values
>theta = Y(:,1);>plot(T,theta)
In this plot it is clear that n = 5 isn’t adequate to represent the function. Type
> hold on
Afterwards redo the above with 5 replaced by 10. Next try 20, 40, 80, and 200. As you are able to see the graph becomes increasingly better as n increases. We are able to compare these calculations with Mat lab’s
built-in function with the commands
> [T Y]= ode45(f,[0 20],[1;-1.5]);>theta = Y(:,1);>plot(T,theta,’r’)
The problem with the Euler method:
You are able to think of the Euler method as finding a linear approximate solution to the initial value problem on each time interval. An apparent shortcoming of the method is that it makes the approximation based on information at the beginning of the time interval only. This problem is demonstrated well by the following IVP:
x¨ + x = 0, x(0) = 1, x? (0) = 0 .
You can effortlessly check that the exact solution of this IVP is
x(t) = cos(t).
If we create the standard change of variables
y1 = x, y2 = x? ,
then we obtain
y?1 = y2, y?2 = −y1.
Then the solution must be y1(t) = cos(t), y2(t) = sin(t). If we after that plot the solution in the (y1, y2) plane, we must get exactly a unit circle. We are able to solve this IVP with Euler’s method:
> g = inline(’[y(2);-y(1)]’,’t’,’y’)> [T Y] = myeuler(g,[0 4*pi],[1;0],20)> y1 = Y(:,1);> y2 = Y(:,2);>plot(y1,y2)
As you are able to see the approximate solution goes far from the true solution. Even if you raise the number of steps the Euler solution will eventually drift outward away from the circle because it doesn’t take into account the curvature of the solution.
The Modified Euler Method:
An idea which is alike to the idea behind the trapezoid method would be to consider f at both the beginning and end of the time step and take the average of the two. Doing this produces the Modified (or else Improved) Euler method represented by the following equations:
k1 = hf (ti, yi)k2 = hf (ti+ h, yi+ k1)yi+1 = yi+1/2(k1 + k2) .
Here k1 captures the information at the start of the time step (same as Euler) while k2 is the information at the end of the time step.
The following program executes the Modified method. It perhaps downloaded from the class web site.
function [T , Y] = mymodeuler(f,tspan,y0,n)% Solves dy/dt = f(t,y) with initial condition y(a) = y0% on the interval [a,b] using n steps of the modified Euler’s method.% Inputs: f -- a function f(t,y) that returns a column vector of the same% length as y% tspan -- a vector [a,b] with the start and end times% y0 -- a column vector of the initial values, y(a) = y0% n -- number of steps to use% Outputs: T -- a n+1 column vector contianing the times% Y -- a (n+1) by d matrix where d is the length of y% Y(t,i) gives the ith component of y at time t% parse starting and ending pointsa = tspan(1);b = tspan(2);h = (b-a)/n; % step sizet = a; y = y0; % t and y are the current variablesT = a; Y = y0’; % T and Y will record all stepsfor i = 1:nk1 = h*f(t,y);k2 = h*f(t+h,y+k1);y = y + .5*(k1+k2);t = a + i*h;T = [T; t];Y = [Y; y’];end
We are able to test this program on the IVP above:
> [T Ym] = mymodeuler(g,[0 4*pi],[1;0],20)> ym1 = Ym(:,1);> ym2 = Ym(:,2);>plot(ym1,ym2)
Latest technology based Matlab Programming Online Tutoring Assistance
Tutors, at the www.tutorsglobe.com, take pledge to provide full satisfaction and assurance in Matlab Programming help via online tutoring. Students are getting 100% satisfaction by online tutors across the globe. Here you can get homework help for Matlab Programming, project ideas and tutorials. We provide email based Matlab Programming help. You can join us to ask queries 24x7 with live, experienced and qualified online tutors specialized in Matlab Programming. Through Online Tutoring, you would be able to complete your homework or assignments at your home. Tutors at the TutorsGlobe are committed to provide the best quality online tutoring assistance for Matlab Programming Homework help and assignment help services. They use their experience, as they have solved thousands of the Matlab Programming assignments, which may help you to solve your complex issues of Matlab Programming. TutorsGlobe assure for the best quality compliance to your homework. Compromise with quality is not in our dictionary. If we feel that we are not able to provide the homework help as per the deadline or given instruction by the student, we refund the money of the student without any delay.
Theory and lecture notes on AC Fundamental Principles and Phasors all along with the key concepts of phasors, angular frequency, cyclic frequency, period, peak voltage, average value and complex phase plane. Tutorsglobe offers homework help, assignment help and tutor’s assistance on AC Fundamental Principles and Phasors.
Transfer of Heat and Heat Capacities tutorial all along with the key concepts of Conduction of Heat, Convection of Heat through Liquids and Gases, Radiation of Heat, Heat capacity, Specific Heat Capacity, Heat capacity of a substance and Newton's Law of Cooling
www.tutorsglobe.com offers Benefits and Pitfalls of Use Cases homework help, assignment help, case study, writing homework help, online tutoring assistance by computer science tutors.
theory of oligopoly and its characteristics, kinked demand curve, www.tutorsglobe.com offers oligopoly assignment help - homework help by live economics tutors help.
identification of the fault in a given tv receiver - very the tv receiver is switched on firstly. there is no picture just only blue retrace lines on the screen.
Structure and Composition of the Atmosphere tutorial all along with the key concepts of Properties of the Atmosphere, Vertical Diminution of Density with Height, Isothermal Atmosphere, Adiabatic Atmosphere, Temperature Profile of Adiabatic Atmosphere
Our apt Feminist thought up to 1980 Assignment Help tutors assist you 24/7 to fetch you notable grades at budget-friendly prices.
Jumstart with our Theories of Human Communication Assignment Help and get authentic and A++ solutions at fair prices!
www.tutorsglobe.com offers Gantt Task and Bonus System homework help, assignment help, case study, writing homework help, online tutoring assistance by accounting tutors.
tutorsglobe.com clinical manifestations of lyme disease assignment help-homework help by online lyme disease tutors
Non-current assets will be apt to be the usual items like machinery and buildings. Cash Flow from financing activities is referred with the long-term financing of the business.
online regents exam preparation course and online regents tutoring package offered by TutorsGlobe are the most comprehensive and customized collection of study resources on the web, offering best collection of regents practice papers, quizzes, regents test papers, and guidance.
first law of thermodynamics tutorial all along with the key concepts of mathematical representation of first law of thermodynamics, internal energy, internal energy as a function of state, isothermal expansion and isothermal reversible expansion
Simply sign up for our Category Theory Assignment Help and secure A++ and unlock a myriad of amazing perks and freebies.
tutorsglobe.com electronic configuration of a molecule assignment help-homework help by online molecular orbital theory tutors
1961394
Questions Asked
3689
Tutors
1455050
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!