Initial Value Problem Presentation-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

WELCOME

TO OUR
PRESENTATION
Group Members:
Student ID Student Name
19MAT061 Md. Nasim Arafat
19MAT062 Taha
19MAT064 Tasnim Faria Zerin
19MAT066 Md. Alamin
19MAT067 Shourave Biswas
19MAT068 Pallob Kumar Das
19MAT069 Sumon Mallick
18MAT018 Kamalesh Bala
18MAT032 Imran Sheikh
18MAT057 Abdur Rahman Masum
2
Course Code : MAT382
Course Title : Numerical Analysis Lab

Course Teacher:
Dr. Dipankar Kumar
Associate Professor
Dept. of Mathematics
BSMRSTU,Gopalganj-8100
3
Topics :
Numerical solutions
of
initial value problem

4
Type of methods:

❖Euler’s method
❖Euler’s Modified method
❖Runge-Kutta 4th order method

In MATLAB

5
EULER’S METHOD

Problem:
Using Euler’s Method RTY
to compute y(0.2) given
𝑑𝑦
that =x+𝑦 2 ,y(0)=1 by taking h=0.02
𝑑𝑥

6
MATLAB Code:
Formula:
clc 𝑦𝑛+1 =𝑦𝑛 +h*f(𝑥𝑛 ,𝑦𝑛 )
clear all
clear all figure
disp('.....input.....')
f=@(x,y) x+(y).^2;
x(1)=input('Enter te initial value of x=');
y(1)=input('Enter the initial value of y(x)=');
h=input('Enter the increment value:');
X=input('Enter the requirement value of X :');
n=(X-x(1))/h;
disp('.....output.....')
for i=1:n
y(i+1)=y(i)+h*f(x(i),y(i));
x(i+1)=x(i)+h;
end
7
for i=2:n+1
fprintf('Value of y at x=%0.2f is %f
\n',x(i),y(i));
end
plot(x,y,’b-*','LineWidth',2)
title('Solving ODE by using Euler
method','Fontsize',16)
xlabel('X-axis','Fontsize',12)
ylabel('Y-axis','Fontsize',12)
legend('required points')
grid minor

8
.....input.....
Enter the initial value of x=0
Enter the initial value of y(x)=1
Enter the increment value:.02
Enter the requirement value of X :.2
.....output.....
Value of y at x=0.02 is 1.020000
Value of y at x=0.04 is 1.041208
Value of y at x=0.06 is 1.063690
Value of y at x=0.08 is 1.087519
Value of y at x=0.10 is 1.112773
Value of y at x=0.12 is 1.139538
Value of y at x=0.14 is 1.167909
Value of y at x=0.16 is 1.197989
Value of y at x=0.18 is 1.229893
Value of y at x=0.20 is 1.263746

9
G Graph

10
EULER’S MODIFIED METHOD

Problem:
Using Euler’s Modified Method with increment
RTY
0.02 to compute the approximate y value
y(0.2) of the solution of the initial value
𝑑𝑦
problem =X+𝑌 2 , y(0)=1
𝑑𝑥

11
MATLAB Code: Formula:
clc 𝑦𝑛+1 ∗ =𝑦𝑛 + ℎ𝑓 𝑥𝑛, , 𝑦𝑛
ℎ ∗ )]
clear all 𝑦𝑛+1 = 𝑦𝑛 + [𝑓 𝑥𝑛 , 𝑦𝑛 + 𝑓(𝑥𝑛+1 , 𝑦𝑛+1
2
clear all figure
disp('.....input.....')
f=@(x,y) x+(y).^2;
x(1)=input('Enter the initial value of x=');
y(1)=input('Enter the initial value of y(x)=');
Type equation here.
h=input('Enter the increment value:');
X=input('Enter the requirement value of X :');
n=(X-x(1))/h;
disp('.....output.....')
for i=1:n
k1= y(i)+h*f(x(i),y(i));
y(i+1)=y(i)+(h/2)*(f(x(i),y(i))+f((x(i)+h),k1));
x(i+1)=x(i)+h;
end
12
for i=2:n+1
fprintf('Value of y at x=%0.2f is %f \n',x(i),
y(i));
end
plot(x,y,'R-*','LineWidth',2)
title('Solving ODE by using Euler Modified
method','Fontsize',16)
xlabel('X-axis','Fontsize',12)
ylabel('Y-axis','Fontsize',12)
legend('required points')
grid minor

13
.....input.....
Enter the initial value of x=0
Enter the initial value of y(x)=1
Enter the increment value:.02
Enter the requirement value of X :.2
.....output.....
Value of y at x=0.02 is 1.020604
Value of y at x=0.04 is 1.042475
Value of y at x=0.06 is 1.065685
Value of y at x=0.08 is 1.090314
Value of y at x=0.10 is 1.116449
Value of y at x=0.12 is 1.144187
Value of y at x=0.14 is 1.173632
Value of y at x=0.16 is 1.204902
Value of y at x=0.18 is 1.238125
Value of y at x=0.20 is 1.273444
14
Graph

15
RUNGE-KUTTA OF 4TH ORDER
METHOD

Problem:
4th Order Method with
Using Runge-Kutta of RTY
increment 0.02 to compute the approximate y
value y(0.2) of the solution of the initial value
𝑑𝑦 𝑦 2 −𝑥 2
problem = 2 2 , y(0)=1 .
𝑑𝑥 𝑦 +𝑥

16
Formula:
𝑘1 = 𝑓(𝑥𝑛, , 𝑦𝑛 )
MATLAB Code: ℎ ℎ
𝑘2 = 𝑓(𝑥𝑛 + ,𝑦 + *k1)
2 𝑛 2
ℎ ℎ
𝑘3 = 𝑓(𝑥𝑛 + ,𝑦 + * 𝑘2 )
2 𝑛 2
𝑘4 = 𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 + h* 𝑘3 )

clear all K= (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
clear all figure 𝑦𝑛+1 = 𝑦𝑛 +k
disp('.....input.....')
f=@(x,y) (y.^2-x.^2)/(y.^2+x.^2);
x(1)=input('Enter the initial value of x=');
y(1)=input('Enter the initial value of y(x)=');
h=input('Enter the increment value:');
X=input('Enter the requirement value of X :');
n=(X-x(1))/h;
disp('.....output.....')

17
for i=1:n
k1=f(x(i),y(i));
k2=f(x(i)+(h/2),y(i)+(h/2)*k1);
k3=f(x(i)+(h/2),y(i)+(h/2)*k2);
k4=f(x(i)+h,y(i)+h*k3);
k=(h/6)*(k1+2*k2+2*k3+k4);
y(i+1)=y(i)+k;
x(i+1)=x(i)+h;
end
for i=2:n+1
fprintf('Value of y at x=%0.2f is %f \n',x(i),y(i));
end
plot(x,y,'b-*','LineWidth',2)
title('Solving ODE by using Runge Kutta 4th order
method','Fontsize',16)
xlabel('X-axis','Fontsize',12)
ylabel('Y-axis','Fontsize',12)
legend('required points')
grid minor

18
.....input.....
Enter the initial value of x=0
Enter the initial value of y(x)=1
Enter the increment value:.02
Enter the requirement value of X :.2
.....output.....
Value of y at x=0.02 is 1.019995
Value of y at x=0.04 is 1.039960
Value of y at x=0.06 is 1.059868
Value of y at x=0.08 is 1.079697
Value of y at x=0.10 is 1.099425
Value of y at x=0.12 is 1.119035
Value of y at x=0.14 is 1.138511
Value of y at x=0.16 is 1.157839
Value of y at x=0.18 is 1.177008
Value of y at x=0.20 is 1.196008

19
Graph

20
Comparing by Exact solution

Problem:
Using Numerical solutions of initial value
problem with increment
RTY 0.1 to compute the
approximate y value y(0.5) of the solution of
𝑑𝑦 1+𝑦 2
the initial value problem = , y(0)=1 .
𝑑𝑥 1+𝑥 2
And compare the solution of Ordinary
Differential Equation.

21
MATLAB Code:

clc
clear all
clear all figure
disp('.....input.....')
f=@(x,y) (1+(y).^2)/(1+(x).^2);
x(1)=input('Enter te initial value of x=');
y(1)=input('Enter the initial value of y(x)=');
h=input('Enter the incremenent value:');
X=input('Enter the requirement value of X :');
n=(X-x(1))/h;
disp('.....output.....')
eu(1)=y(1);

22
for i=1:n
eu(i+1)=eu(i)+h*f(x(i),eu(i));
x(i+1)=x(i)+h;
end
eum(1)=y(1);
for i=1:n
k1=eum(i)+h*f(x(i),eum(i));

eum(i+1)=eum(i)+(h/2)*(f(x(i),eum(i))+f((x(i
)+h),k1));
x(i+1)=x(i)+h;
end
ru4(1)=y(1);

23
for i=1:n
k1=f(x(i),ru4(i));
k2=f(x(i)+(h/2),ru4(i)+(h/2)*k1);
k3=f(x(i)+(h/2),ru4(i)+(h/2)*k2);
k4=f(x(i)+h,ru4(i)+h*k3);
k=(h/6)*(k1+2*k2+2*k3+k4);
ru4(i+1)=ru4(i)+k;
y(i+1)=x(i).^2/(1-6*x(i));
x(i+1)=x(i)+h;
end
for i=2:n+1
fprintf('values of x=%f\n Eulers
method=%f\n Eulers modified method=%f\n
Rung-Kutta method=%f\n\n
',x(i),eu(i),eum(i),ru4(i));
end

24
plot(x,eu,'g->','linewidth',3)
hold on
plot(x,eum,'k-*','LineWidth',2)
hold on
plot(x,ru4,'r-<','LineWidth',2)
hold on
for i=2:n+1
y(i)=(1+x(i))/(1-x(i));
end
plot(x,y,'b-*')
title('Comparing by Exact solution','Fontsize',16)
xlabel('X-axis','Fontsize',12)
ylabel('Y-axis','Fontsize',12)
hold off
legend('Euler method','Euler Modified','Runge-
Kutta method','Exact soluation','location','best')

25
.....input.....
Enter the initial value of x=0
Enter the initial value of y(x)=1
Enter the increment value:.1
Enter the requirement value of X :.6
.....output.....
values of x=0.100000
Eulers method=1.200000
Eulers modified method=1.220792
Runge-Kutta method=1.222222

values of x=0.200000
Eulers method=1.441584
Eulers modified method=1.495669
Runge-Kutta method=1.499998

values of x=0.300000
Eulers method=1.737562
Eulers modified method=1.846936
Runge-Kutta method=1.857133
26
values of x=0.400000
Eulers method=2.106288
Eulers modified method=2.310915
Runge-Kutta method=2.333296

values of x=0.500000
Eulers method=2.574948
Eulers modified method=2.950816
Runge-Kutta method=2.999869

27
Graph

28
Thank you
For watching

29

You might also like