You are on page 1of 14

Nama: Syahputri Aprellia

Kelas: 2 EGA

NIM: 062040410404

Mata Kuliah: Metode Numerik

Dosen Pengampu: Dr.Yulianto Wasiran, M.M

18-06-2021

a)Matlab

function rungekutta2
x = 0;
y = 1;
xn = 2;
h = 0.2;
N = (xn-x)/h;
fprintf('step 0: x = %12.2f, y = %12.6f\n',x,y);
for i=1:N
k1 = h*f(x,y);
k2 = h*f(x+h,y+k1);
y=y+(k1+k2)/2;
x= x + h;
fprintf('step %d: x = %12.2f, y = %12.6f\n',i, x, y);
end
%%%%%%%%%%%%
function v = f(x,y)
v = 1+y^2;
hasil run:

>> rungekutta2

step 0: x = 0.00, y = 1.000000

step 1: x = 0.20, y = 1.496000

step 2: x = 0.40, y = 2.379305

step 3: x = 0.60, y = 4.522955

step 4: x = 0.80, y = 14.537996

step 5: x = 1.00, y = 360.872080

step 6: x = 1.20, y = 69745312.167847

step 7: x = 1.40, y = 94649896490627314000000000000.000000


step 8: x = 1.60, y =
32102626408709586000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000.000000

step 9: x = 1.80, y = Inf

step 10: x = 2.00, y = Inf

b)Excel

c)Manual
:°* lix „,)

: o.'l*. ,tw*)

O.›. °*°'*. ****°.*S+‹l


'
#':s•*:›l'.*•.l

. t°")

- o . i . + I i + t , I ; ise. ins i t ceii. ii r* )

- o.› .+ l ' , 4 * a . › ; s.xc.‹•“ + › ,s+ . c•”)


” ’ *‘ ” *‘ *‘ "
a)Matlab

function rungekutta2
x = 0;
y = 0;
xn = 1;
h = 0.1;
N = (xn-x)/h;
fprintf('step 0: x = %12.2f, y = %12.6f\n',x,y);
for i=1:N
k1 = h*f(x,y);
k2 = h*f(x+h,y+k1);
y=y+(k1+k2)/2;
x= x + h;
fprintf('step %d: x = %12.2f, y = %12.6f\n',i, x, y);
end
%%%%%%%%%%%%
function v = f(x,y)
v = y-x+2;
hasil run:

>> rungekutta2

step 0: x = 0.00, y = 0.000000

step 1: x = 0.10, y = 0.205000

step 2: x = 0.20, y = 0.421025

step 3: x = 0.30, y = 0.649233

step 4: x = 0.40, y = 0.890902

step 5: x = 0.50, y = 1.147447

step 6: x = 0.60, y = 1.420429

step 7: x = 0.70, y = 1.711574

step 8: x = 0.80, y = 2.022789

step 9: x = 0.90, y = 2.356182

step 10: x = 1.00, y = 2.714081

b)Excel

c)Manual
- 0 b11 IO z$

.o, ( o,c43n1r . o . ¿, )

' o, .{( °. l0, i ; o, mr › o, ,<)


litre; G -c

• A'.]( °S+0.i ; 0,*809o 0.14$o ,p, ( qgg¿

* k : 0,g + a , \
a)Matlab

function rungekutta2
x = 0;
y = 1;
xn = 3;
N = 4;
h = (xn-x)/N;
fprintf('step 0: x = %12.2f, y = %12.6f\n',x,y);
for i=1:N
k1 = h*f(x,y);
k2 = h*f(x+h,y+k1);
y=y+(k1+k2)/2;
x= x + h;
fprintf('step %d: x = %12.2f, y = %12.6f\n',i, x, y);
end
%%%%%%%%%%%%
function v = f(x,y)
v = (x-y)/2;

hasil run:

>> rungekutta2

step 0: x = 0.00, y = 1.000000

step 1: x = 0.75, y = 0.835938

step 2: x = 1.50, y = 0.950378

step 3: x = 2.25, y = 1.258466

step 4: x = 3.00, y = 1.701199

b)Excel

c)Manual
0. sl,S ' D,9i0] )

. 0,1., D f O ,/s i l t (•O,$IT})

-0,4t0o6[

. 0, 0#60A
O,B oSM + q ¿pt ## t o,etoo;6)

y, : X°fk, o + °,>; : o,+t


\‹0,tAS8 8

. D,M- £ o
* O,S1 Cu}
a)Matlab

function rungekutta2
x = 0;
y = 2;
xn = 4;
N = 4;
h = (xn-x)/N;
fprintf('step 0: x = %12.2f, y = %12.6f\n',x,y);
for i=1:N
k1 = h*f(x,y);
k2 = h*f(x+h,y+k1);
y=y+(k1+k2)/2;
x= x + h;
fprintf('step %d: x = %12.2f, y = %12.6f\n',i, x, y);
end
%%%%%%%%%%%%
function v = f(x,y)
v = x*y+x;
hasil run:

>> rungekutta2

step 0: x = 0.00, y = 2.000000

step 1: x = 1.00, y = 3.500000

step 2: x = 2.00, y = 14.750000

step 3: x = 3.00, y = 101.375000

step 4: x = 4.00, y = 1073.937500

b)Excel

c)Manual
+¥:t. lx›,y,)
:1.tl;: t°'•3 T)

: i.{l*; t)

You might also like