Clear Filters
Clear Filters

Forward Euler method for Higher order differential equation

20 views (last 30 days)
Helloo!
I am trying to solve a third order differential equation using forward euler method. The differential equation is : y''' = 2 y'' + 6y ; y(0) =1, y'(0) = 0, y''(0)=1, interval is [0, 5], step size= 0.001. here the derivative is with respect to time (t). I dont know how to proceed further and do the iteration. I tried to change the above differential equation into a first order differential equation but then I dont know how to proceed with the code.
y(1) = y ;
y(2) = y' = y(1)'
y(3) = y'' = y(2)'
y(3)' = 2 y(3) + 6 y(1)
Below is a code which I used to solve first order differential equation using euler method. Please help.
clear
close all
clc
%%
t0 = 0; %initial value
y0 = 1; %initial condition(given)
tEnd = 5; %end of time step
h = 0.001; %step size
N = (tEnd-t0)/h; %number of interval
T = t0:h:tEnd;
Y = zeros(1, N+1);
Y(1) = y0;
for i = 1:N
fi = %function
Y(i+ 1) = Y(i) + h * fi;
end
%%
%ploting===================================================================
plot(T,Y,'.','LineWidth',2);
title('Approximate solution Euler Explicit Method')

Accepted Answer

James Tursa
James Tursa on 28 Apr 2020
You need to think of Y as your three element column vector as you have defined. So at each step you are dealing with a column vector. E.g.,
Y = zeros(3, N+1); % <-- a series of 3-element column vectors
Y(:,1) = [1;0;1]; % <-- initial value is a 3-element column vector of [ y ; y' ; y'' ]
for i = 1:N
fi = %function, which needs to calculate a 3-element derivative column vector
Y(:,i+1) = Y(:,i) + h * fi; % <-- each step works with columns of Y
  2 Comments
Hrishikesh Das
Hrishikesh Das on 28 Apr 2020
In case of a third order derivative how to write the function? As I have converted it into a first order using other vriables. plz help.
James Tursa
James Tursa on 28 Apr 2020
Edited: James Tursa on 28 Apr 2020
Just take your definitions:
y(2) = y' = y(1)'
y(3) = y'' = y(2)'
y(3)' = 2 y(3) + 6 y(1)
and write a 3-element fi vector based on that. The outline is
fi = [ y(1)' ; y(2)' ; y(3)' ]; % <-- you fill this in based on the above three lines
Now you fill in the above three elements based on your definitions in terms of y(1), y(2), and y(3), and that becomes your code. E.g., that first spot for y(1)' using your definitions is simply y(2), so y(2) would be the first element of fi. But remember we are dealing with columns of Y in your actual code, so for you actual code y(2) at time point i is Y(2,i). So you would have
fi = [ Y(2,i) ; y(2)' ; y(3)' ]; % <-- you fill this in based on the above three lines
Do this for the other two elements.

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 28 Apr 2020
You can download the zip file given in this answer: https://www.mathworks.com/matlabcentral/answers/98293-is-there-a-fixed-step-ordinary-differential-equation-ode-solver-in-matlab-8-0-r2012b#answer_107643 and study the code of ode1.m. It is the implementation of the Euler method provided by Mathworks in very early releases of MATLAB. It is no longer included in MATLAB by default, but it is still useful to understand the implementation of the Euler method for higher-order ODEs.
  4 Comments
Hrishikesh Das
Hrishikesh Das on 28 Apr 2020
Are you talking about this file? I took a quick look but I am not getting this properly.
Ameer Hamza
Ameer Hamza on 28 Apr 2020
You can see James' answer. You can follow that hint to implement multiple ODEs using Euler.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!