Anda di halaman 1dari 8

# PERSAMAAN NON LINEAR

x y x2 0,5
y x2 5xy

## Tentukan nilai x dan y untuk tebakan awal x=y=1

a.Dengan metode Newton
Script File

U=inline('x-y-x^2+0.5');
dUdx=inline('1-2*x');
dUdy=-1;
V=inline('y-x^2+5*x*y');
dVdx=inline('5*y-2*x');
dVdy=inline('5*x+1');
x(1)=1;y(1)=1;
x(2)=x(1)-((U(x(1),y(1))*dVdy(x(1))-(V(x(1),y(1))*dUdy))/
(dUdx(x(1))*dVdy(x(1))-(dUdy*dVdx(x(1),y(1)))))
y(2)=y(1)-((V(x(1),y(1))*dUdx(x(1))-(U(x(1),y(1))*dVdx(x(1),y(1))))/
(dUdx(x(1))*dVdy(x(1))-(dUdy*dVdx(x(1),y(1)))))
x(3)=x(2)-((U(x(2),y(2))*dVdy(x(2))-(V(x(2),y(2))*dUdy))/
(dUdx(x(2))*dVdy(x(2))-(dUdy*dVdx(x(2),y(2)))))
y(3)=y(2)-((V(x(2),y(2))*dUdx(x(2))-(U(x(2),y(2))*dVdx(x(2),y(2))))/
(dUdx(x(2))*dVdy(x(2))-(dUdy*dVdx(x(2),y(2)))))
x(4)=x(3)-((U(x(3),y(3))*dVdy(x(3))-(V(x(3),y(3))*dUdy))/
(dUdx(x(3))*dVdy(x(3))-(dUdy*dVdx(x(3),y(3)))))
y(4)=y(3)-((V(x(3),y(3))*dUdx(x(3))-(U(x(3),y(3))*dVdx(x(3),y(3))))/
(dUdx(x(3))*dVdy(x(3))-(dUdy*dVdx(x(3),y(3)))))

## Save dengan nama Persamaan Non Linear

Command Window
>> PersamaanNonLinear
>> [x;y]
ans =
1.0000 1.6667 1.3398 1.2421
1.0000 -0.1667 0.1517 0.2088

## b. Dengan menggunakan Fsolve

M-File
function [f]=menggunakanFsolve(x)
%persamaan non linear x(1)=x, x(2)=y
f(1)=x(1)-x(2)-x(1)^2+0.5;
f(2)=x(2)-x(1)^2+5*x(1)*x(2);
f=[f(1);f(2)];
Simpan dengan nama menggunakanFsolve
Command Window

## >> hargaxdany=fsolve(@menggunakanFsolve,[1 1])

PERSAMAAN DIFERENSIAL
1.PERSAMAAN DIFERENSIAL TUNGGAL
1.a Metode Euleur
Diketahui persamaan diferensial tunggal sebagai berikut

dy xe y
dx

Ketika x=0,y=0
Tentukan harga y ketika y=0,5 dengan 5 langkah.
Script File

f1=inline('x*exp(y)');
deltax=0.1;
x=[0 0.1 0.2 0.3 0.4 0.5];
y(1)=0;
y(2)=y(1)+deltax*f1(x(1),y(1));
y(3)=y(2)+deltax*f1(x(2),y(2));
y(4)=y(3)+deltax*f1(x(3),y(3));
y(4)=y(3)+deltax*f1(x(3),y(3));
y(5)=y(4)+deltax*f1(x(4),y(4));
y(6)=y(5)+deltax*f1(x(5),y(5));
[x;y]

Command Window
>> EulerTunggal
ans =
x
0
0.1000 0.2000
y
0
0
0.0100
1.b Metode Kutta

0.3000
0.0302

0.4000 0.5000
0.0611 0.1036

Script File
f1=inline('x*exp(y)');
deltax=0.25;
y(1)=0;
x=[0 0.25 0.5];
k1(1)=f1(x(1),y(1));
k2(1)=f1(x(1)+deltax/2,y(1)+k1(1)*deltax/2);
k3(1)=f1(x(1)+deltax/2,y(1)+k2(1)*deltax/2);
k4(1)=f1(x(1)+deltax,y(1)+k3(1)*deltax);
y(2)=y(1)+(deltax/6)*(k1(1)+2*k2(1)+2*k3(1)+k4(1));
k1(2)=f1(x(2),y(2));
k2(2)=f1(x(2)+deltax/2,y(2)+k1(2)*deltax/2);
k3(2)=f1(x(2)+deltax/2,y(2)+k2(2)*deltax/2);
k4(2)=f1(x(2)+deltax,y(2)+k3(2)*deltax);
y(3)=y(2)+(deltax/6)*(k1(2)+2*k2(2)+2*k3(2)+k4(2))

Command Window
>> kuttatunggal
y=
0
0.0317
0.1335
1.c ODE 45
Command Window
>> f1=inline('x*exp(y)');
>> [x,y]=ode45(f1,[0:0.25:0.5],0)
x=
0
0.2500
0.5000
y=
0
0.0317
0.1335

Soal Baru
dy/dx=-2y+5e^-x
dz/dx=-yz^2/2
x=0,y=2,z=4

x=1,y=?,z=?
1. METODE ODE45
m-File
%z=y(2)
function f=latihanUTS2(x,y);
f(1)=-2*y(1)+5*exp(-x);
f(2)=-y(1)*y(2)^2/2;
f=[f(1);f(2)];
save : latihanUTS2
>> format short
>> [x,y]=ode45(@latihanUTS2,[0:0.25:1],[2 4])
x =
0
0.2500
0.5000
0.7500
1.0000
y =
2.0000
2.0744
1.9290
1.6924
1.4334

4.0000
1.9690
1.3166
1.0138
0.8462

2. METODE EULER
>> f=inline('-2*y+5*exp(-x)')
f =
Inline function:
f(x,y) = -2*y+5*exp(-x)
>> g=inline('-y*z^2/2')
g =
Inline function:
g(y,z) = -y*z^2/2
>> deltax=0.2;
>> x=[0 0.2 0.4 0.6 0.8 1];

>> clear y
>> y(1)=2;z(1)=4;
>> y(2)=y(1)+deltax*f(x(1),y(1))
y =
2.0000

2.2000

>> z(2)=z(1)+deltax*g(y(1),z(1))
z =
4.0000

0.8000

>> y(3)=y(2)+deltax*f(x(2),y(2))
y =
2.0000

2.2000

2.1387

>> z(3)=z(2)+deltax*g(y(2),z(2))
z =
4.0000

0.8000

0.6592

...diteruskan

## 2.PERSAMAAN DIFERENSIAL BANYAK

1. Metode Euler
f1=inline('x*y1*y2/y3');
f2=inline('x^2+y1^2+y2^2+y3^2');
f3=inline('(y1*y2+y2*y3+y1*y3)*x');
x=[0 0.1 0.2 0.3];
deltax=0.1;
y1(1)=1;y2(1)=1;y3(1)=1;
y1(2)=y1(1)+deltax*f1(x(1),y1(1),y2(1),y3(1));
y2(2)=y2(1)+deltax*f2(x(1),y1(1),y2(1),y3(1));
y3(2)=y3(1)+deltax*f3(x(1),y1(1),y2(1),y3(1));
y1(3)=y1(2)+deltax*f1(x(2),y1(2),y2(2),y3(2));
y2(3)=y2(2)+deltax*f2(x(2),y1(2),y2(2),y3(2));
y3(3)=y3(2)+deltax*f3(x(2),y1(2),y2(2),y3(2));
y1(4)=y1(3)+deltax*f1(x(3),y1(3),y2(3),y3(3))
y2(4)=y2(3)+deltax*f2(x(3),y1(3),y2(3),y3(3))

y3(4)=y3(3)+deltax*f3(x(3),y1(3),y2(3),y3(3))

Command Window
>> EulerBanyak
y1 =
1.0000
1.0000
1.0130
1.0457
y2 =
1.0000
1.3000
1.6700
2.1628
y3 =
1.0
1.0000
1.0360
1.1254

2. Metode Kutta
Script File

f1=inline('x*y1*y2/y3');
f2=inline('x^2+y1^2+y2^2+y3^2');
f3=inline('(y1*y2+y2*y3+y1*y3)*x');
x=[0 0.1 0.2 0.3];
delx=0.1;
y1(1)=1;y2(1)=1;y3(1)=1;
k11(1)=f1(x(1),y1(1),y2(1),y3(1));
k12(1)=f2(x(1),y1(1),y2(1),y3(1));
k13(1)=f3(x(1),y1(1),y2(1),y3(1));
k21(1)=f1(x(1)+delx/2,y1(1)+k11(1)*delx/2,y2(1)+k12(1)*delx/2,y3(1)+k13(1)*del
x/2);
k22(1)=f2(x(1)+delx/2,y1(1)+k11(1)*delx/2,y2(1)+k12(1)*delx/2,y3(1)+k13(1)*del
x/2);
k23(1)=f3(x(1)+delx/2,y1(1)+k11(1)*delx/2,y2(1)+k12(1)*delx/2,y3(1)+k13(1)*del
x/2);

k31(1)=f1(x(1)+delx/2,y1(1)+k21(1)*delx/2,y2(1)+k22(1)*delx/2,y3(1)+k23(1)*del
x/2);
k32(1)=f2(x(1)+delx/2,y1(1)+k21(1)*delx/2,y2(1)+k22(1)*delx/2,y3(1)+k23(1)*del
x/2);
k33(1)=f3(x(1)+delx/2,y1(1)+k21(1)*delx/2,y2(1)+k22(1)*delx/2,y3(1)+k23(1)*del
x/2);
k41(1)=f1(x(1)+delx,y1(1)+k31(1)*delx,y2(1)+k32(1)*delx,y3(1)+k33(1)*delx);
k42(1)=f2(x(1)+delx,y1(1)+k31(1)*delx,y2(1)+k32(1)*delx,y3(1)+k33(1)*delx);
k43(1)=f3(x(1)+delx,y1(1)+k31(1)*delx,y2(1)+k32(1)*delx,y3(1)+k33(1)*delx);
y1(2)=y1(1)+(delx/6)*(k11(1)+2*k21(1)+2*k31(1)+k41(1));
y2(2)=y2(1)+(delx/6)*(k12(1)+2*k22(1)+2*k32(1)+k42(1));
y3(2)=y3(1)+(delx/6)*(k13(1)+2*k23(1)+2*k33(1)+k43(1));
k11(2)=f1(x(2),y1(2),y2(2),y3(2));
k12(2)=f2(x(2),y1(2),y2(2),y3(2));
k13(2)=f3(x(2),y1(2),y2(2),y3(2));
k21(2)=f1(x(2)+delx/2,y1(2)+k11(2)*delx/2,y2(2)+k12(2)*delx/2,y3(2)+k13(2)*del
x/2);
k22(2)=f2(x(2)+delx/2,y1(2)+k11(2)*delx/2,y2(2)+k12(2)*delx/2,y3(2)+k13(2)*del
x/2);
k23(2)=f3(x(2)+delx/2,y1(2)+k11(2)*delx/2,y2(2)+k12(2)*delx/2,y3(2)+k13(2)*del
x/2);
k31(2)=f1(x(2)+delx/2,y1(2)+k21(2)*delx/2,y2(2)+k22(2)*delx/2,y3(2)+k23(2)*del
x/2);
k32(2)=f2(x(2)+delx/2,y1(2)+k21(2)*delx/2,y2(2)+k22(2)*delx/2,y3(2)+k23(2)*del
x/2);
k33(2)=f3(x(2)+delx/2,y1(2)+k21(2)*delx/2,y2(2)+k22(2)*delx/2,y3(2)+k23(2)*del
x/2);
k41(2)=f1(x(2)+delx,y1(2)+k31(2)*delx,y2(2)+k32(2)*delx,y3(2)+k33(2)*delx);
k42(2)=f2(x(2)+delx,y1(2)+k31(2)*delx,y2(2)+k32(2)*delx,y3(2)+k33(2)*delx);
k43(2)=f3(x(2)+delx,y1(2)+k31(2)*delx,y2(2)+k32(2)*delx,y3(2)+k33(2)*delx);
y1(3)=y1(2)+(delx/6)*(k11(2)+2*k21(2)+2*k31(2)+k41(2))
y2(3)=y2(2)+(delx/6)*(k12(2)+2*k22(2)+2*k32(2)+k42(2))
y3(3)=y3(2)+(delx/6)*(k13(2)+2*k23(2)+2*k33(2)+k43(2))

Command window

>> kuttabanyak
y1 =
1.0000 1.0061
y2 =
1.0000 1.3378
y3 =
1.0000 1.0173

1.0290

1.0457

1.7954

2.1628

1.0823

1.1254

3. Metode
M-FILE

ODE 45

function f=perdifbanyak1(x,y)
%penyelesaian persamaan 3 diferensial
f(1)=x*y(1)*y(2)/y(3);
f(2)=x^2+y(1)^2+y(2)^2+y(3)^2;
f(3)=(y(1)*y(2)+y(2)*y(3)+y(1)*y(3))*x;
f=[f(1);f(2);f(3)];

## >> [x,y]=ode45(@perdifbanyak1,[0:0.1:0.3],[1 1 1])

y=
1.0000 1.0000 1.0000
1.0061 1.3378 1.0173
1.0290 1.7954 1.0823
1.0778 2.4962 1.2308
>> [x y]
ans =
x
y1
y2
y3
0
1.0000 1.0000 1.0000
0.1000 1.0061 1.3378 1.0173
0.2000 1.0290 1.7954 1.0823
0.3000 1.0778 2.4962 1.2308

## Menentukan Nilai Maksimum

1. Variabel Tunggal
Cek Grafik fungsi
SOAL
Maks : f(x)=2x-1.75x^2+1.1x^3-0.25x^4
>>y=inline('2*x-1.75*x.^2+1.1*x.^3-0.25*x.^4')
>>plot([0:0.1:5],y([0:0.1:5]))
>> hargaxmaks=fminbnd('-(2*x-1.75*x.^2+1.1*x.^3-0.25*x.^4)',-1,5)
hargaxmaks =
2.0793
>> hargaxmin=fminbnd('(2*x-1.75*x.^2+1.1*x.^3-0.25*x.^4)',-1,5)
hargaxmin =
4.9999