matlab2
-
Upload
singgih-prana-putra -
Category
Documents
-
view
2 -
download
0
description
Transcript of matlab2
NAMA : SINGGIH PRANA PUTRA
NIM : 1203121071
KELAS : FISIKA KOMPUTASI – B
TUGAS : 2
1. Buatlah pada matlab kodingnya dari fungsi berikut menggunakan Metode Interpolasi Lagrange:
X -1 0 3 6 7y 3 -6 39 922 1611
Jawab :
Bentuk M-file- nya ialah :
% Pembuktian nilai X dengan menggunakan Metode Interpolasi Lagrange %X=input('X=')x0=input('x0=');y0=input('y0=');x1=input('x1=');y1=input('y1=');x2=input('x2=');y2=input('y2=');x3=input('x3=');y3=input('y3=');x4=input('x4=');y4=input('y4='); Y0=y0*[((X-x1)*(X-x2)*(X-x3)*(X-x4))/((x0-x1)*(x0-x2)*(x0-x3)*(x0-x4))]Y1=y1*[((X-x0)*(X-x2)*(X-x3)*(X-x4))/((x1-x0)*(x1-x2)*(x1-x3)*(x1-x4))]Y2=y2*[((X-x1)*(X-x0)*(X-x3)*(X-x4))/((x2-x1)*(x2-x0)*(x2-x3)*(x2-x4))]Y3=y3*[((X-x1)*(X-x2)*(X-x0)*(X-x4))/((x3-x1)*(x3-x2)*(x3-x0)*(x3-x4))]Y4=y4*[((X-x1)*(X-x2)*(X-x3)*(X-x0))/((x4-x1)*(x4-x2)*(x4-x3)*(x4-x0))] P5=Y0+Y1+Y2+Y3+Y4
Maka hasil run-nya dan eksekusinya ialah:
>> Trial2
X=5
X =
5
x0=-1
y0=3
x1=0
y1=-6
x2=3
y2=39
x3=6
y3=822
x4=7
y4=1611
Y0 =
0.2679
Y1 =
1.1429
Y2 =
16.2500
Y3 =
782.8571
Y4 =
-431.5179
P5 =
369