You are on page 1of 9

Mindanao State University

Fatima, General Santos City

_________________________________________________________

College of Engineering

_________________________________________________________

Numerical Methods ES 84

EE

_________________________________________________________

First Semester

School Year 2015-2016

Tuesdays and Fridays 1:00-2:30pm

_________________________________________________________

Laboratory Report

Euler Method

_________________________________________________________

Engr. Rebecca Ruth R.Salas

ES 84

Yabes, Jasper Brylle

2012-1410
Introduction

In mathematics and computational science, the Euler method is a

SN-order numerical procedure for solving ordinary differential equations

(ODEs) with a given initial value. It is the most basic explicit method for

numerical integration of ordinary differential equations and is the simplest

RungeKutta method. The Euler method is named after Leonhard Euler,

who treated it in his book Institutionum calculi integralis (published 1768

70).

Engineering Problem Posed

The task is to implement a routine of Euler's method and then to use

it to solve the given example of Newton's cooling law with it for three

different step sizes of 2 s, 5 s and 10 s and to compare with the analytical

solution. The initial temperature T 0 shall be 100 C, the room temperature

TR
20 C, and the cooling constant k 0.07. The time interval to calculate

shall be from 0 s to 100 s.

Mathematical Modeling

Newton's cooling law describes how an object of initial temperature T(

to
) = T 0 cools down in an environment of temperature T R :
dT (t )
=kT
dt

or

dT (t )
=k (T ( t )T R )
dt

dT (t )
It says that the cooling rate dt of the object is proportional to the

current temperature difference T =(T ( t )T R ) to the surrounding

environment.

Analytical Solution

dT (t )
Giving the ordinary differential equation: =k (T ( t )T R )
dt

Integrating it, becomes:

T ( t )=T R +(T 0 T R )ekt

Using the given values:

T ( t )=20+(10020)e0.07t
Substituting the initial condition form 0 to 100 to the t variable, results

a graph of temperature with respect to time (s). Showing the graph below is

the comparison of true value to the approximated one.

Numerical Solution

y i+1= yi + f ( xi , y i ) h
Equation can be used to implement Eulers method

(for x=0 only, some solutions are not viewed):

y ( 0.07 )= y ( 0 ) + f ( 0,100 ) 0.07

Where y ( 0 )=100 and the slope estimates at x=0 is


f ( 0, 100 )=0.07 ( 0 )+1.4=1.4

Therefore,

y ( 0.07 )=100+1.4 ( 0.07 )=100.095

Source Code

package es84finals;

public class EULER {private static void euler (Callable f, double y0, int a, int
b, int h) {
int t = a;
double y = y0;
while (t < b) {
System.out.println ("" + t + " " + y);
t += h;
y += h * f.compute (t, y);
}
System.out.println ("DONE");
}

public static void main (String[] args) {


Callable cooling = new Cooling ();
int[] steps = {2, 5, 10};
for (intstepSize : steps) {
System.out.println ("Step size: " + stepSize);
euler (cooling, 100.0, 0, 100, stepSize);
}
}
}

// interface used so we can plug in alternative functions to Euler


interface Callable {
public double compute (int time, double t);
}

// class to implement the newton cooling equation


class Cooling implements Callable {
@Override
public double compute (int time, double t) {
return -0.07 * (t - 20);
}
}
Screenshots
Conclusion

The Euler method is a first-order method, which means that the local

error (error per step) is proportional to the square of the step size, and the

global error (error at a given time) is proportional to the step size. The Euler

method often serves as the basis to construct more complex methods.

The Euler method is a first-order method, which means that the local

error (error per step) is proportional to the square of the step size, and the

global error (error at a given time) is proportional to the step size. The

bigger the size of the initial condition is the larger the error becomes. It is

not very suitable for large initial condition.

You might also like