0% found this document useful (0 votes)
8 views3 pages

Home task

Uploaded by

Arshman Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Home task

Uploaded by

Arshman Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

National University of Science and Technology

College of E&ME
Department of Mechatronics Engineering

LAB TASKS
TASK 1:

Construct a program to Euler’s Method and 2nd order R-K Method to solve the following initial
value problem

y'=y - (t^2) + 1 y(0)=0.5

Keep your step size h=0.5 and solve till t=2. Repeat for h=0.05

TASK 2:

Construct a program to implement 4th order R-K Method to solve the following initial value
problem
𝑚𝑚𝑥𝑥̈ + 𝑐𝑐𝑥𝑥̇ + 𝑘𝑘𝑘𝑘 = cos 3𝑡𝑡

Use m=1, c=2, k=4. Solve for initial velocity, 𝑥𝑥̇ (0) = 0 ; and an initial displacement, 𝑥𝑥(0) = 1.
Plot displacement vs time. Use an appropriate time step and end time to capture the dynamics of the
system.

Note that the 2nd order equation can be converted in to two first order equations, using a newly defined
set of “state variables” 𝑥𝑥1 = 𝑥𝑥 and 𝑥𝑥2 = 𝑥𝑥̇
𝑥𝑥̇ 1 = 𝑥𝑥2
𝑥𝑥̇ 2 = cos 3𝑡𝑡 − 2𝑥𝑥2 − 4𝑥𝑥1

LAB 10

Aim:
The main aim for this lab is to learn about the following topics:
• Euler’s Method

Software Required:
• MATLAB
EULER’s METHOD:
Without explicit solutions to the differential equations it would be hard to get any information about
the solution.
For instance, maybe we need to determine how a specific solution behaves, including some values
that the solution will take. There are also a fairly large set of differential equations that are not easy
to sketch good direction fields for.
There are many different methods that can be used to approximate solutions to a differential
equation. This method was originally devised by Euler and is called, oddly enough, Euler’s Method.

Let’s start with a general first order IVP

where f(t,y) is a known function and the values in the initial condition are also known numbers. We
want to approximate the solution to (1) near t=t0 . We’ll start with the two pieces of information that
we do know about the solution. First, we know the value of the solution at t=t0 from the initial
condition. Second, we also know the value of the derivative at t=t0 . We can get this by plugging the
initial condition into f(t,y) into the differential equation itself. So, the derivative at this point is.

Take a look at the figure below

If h is the step size then the formula for the next approximation becomes.

Euler’s Method can be defined in steps as:


1. define .
2. input t0 and y0.
3. input step size, h and the number of steps, n.
4. for j from 1 to n do
a. m = f (t0, y0)
b. y1 = y0 + h*m
c. t1 = t0 + h
d. Print t1 and y1
e. t0 = t1
f. y0 = y1
5. end
LAB 11

Aim:
The main aim for this lab is to learn about the following topics:
• 2nd order R.K Method
• 4th order R.K Method

Software Required:
• MATLAB

Runge Kutta Method:


Runge-Kutta methods are a class of methods which judiciously uses the information on the 'slope' at
more than one point to extrapolate the solution to the future time step. A method of numerically
integrating ordinary differential equations by using a trial step at the midpoint of an interval to cancel
out lower-order error terms is called Runge Kutta Method.

2nd Order RK method:


The second-order RK method’s formula is as under:

K1 = h f ( xi , yi )
K2 = h f( xi + h , yi + K1 )
Yi+1 = yi + ( K1 + K2 ) / 2

4th Order RK method:


The formula for the fourth order Runge-Kutta method (RK4) is given below:

K1 = h f ( xi , yi )
K2 = h f ( xi + h / 2 , yi + K1 / 2)
K3 = h f ( xi + h / 2 , yi + K2 / 2)
K4 = h f( xi + h , yi + K3 )

Yi+1 = yi + ( K1 + 2K2 + 2K3 + K4 ) / 6

Where f(x,y) = dy / dx
Y(t0) = α
α is the initial value of y.

You might also like