Sie sind auf Seite 1von 8

CURVE FITTING & INTERPOLATIONS

1. x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1];
y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];
plot(x,y,-o)

12

10

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

2. n = 2; p = polyfit(x,y,n)
p = -9.8108 20.1293 -0.0317
p= 9.8108 + 20.1293x 0.0317x 2
3. a. xi = linspace(0,1,100);
yi = polyval(p,xi);
figure,plot(x,y,-o,xi,yi, :)

12

10

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
b. pp = polyfit(x,y,10) ;
z = polyval(pp,xi);
figure, plot(x,y,o,xi,z,: )

16

14

12

10

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Pada gambar 4a dan 4b mempunyai tempat titik yang sama, namun perbedaannya terdapat
pada titik rentang masing-masing titik x dan y. Rentang utuk gambar 4a adalah 100 titik
sehingga garis terlihat lebih halus daripada gambar 4b yang berentang 10 titik.

4. x1 = linspace(0 , 2*pi, 60);


x2 = linspace(0 , 2*pi, 6) ;
figure, plot(x1 , sin(x1) )
figure, plot(x2 , sin(x2) , )
figure, plot(x1 , sin(x1), x2 , sin(x2) , ) ), grid on
xlabel(x), ylabel(Sin(x)) , title(Linear Interpolation)
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7

linear interpolation
1

0.8

0.6

0.4

0.2
sin(x)

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
x
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7

5. Hz = [ 20:10:100 200:100:1000 1500 2000:1000:10000]; % frequencies in Herzt


spl = [76 66 59 54 49 46 43 40 38 22 14 9 6 3.5 2.5 1.4 0.7 0 -1 -3 -8 -7 -2 2 7 9 11 12 ];
% Sound pressure level in dB
semilogx(Hz,spl,'-o')
xlabel('Frequency, Hz')
ylabel('Relative Sound Pressure Level, dB')
title('Threshold of Human Hearing')
grid on
s = interp1(Hz,spl,2.5e3)
s = interp1(Hz,spl,2.5e3,'linear')
s = interp1(Hz,spl,2.5e3,'spline')
s = interp1(Hz,spl,2.5e3,'cubic')
s = interp1(Hz,spl,2.5e3,'nearest')
Answer
s = -5.5000
s = -5.5000
s = -5.8690
s = -6.0488
s =-8
Threshold of Human Hearing
80

70
Relative Sound Pressure Level,dB

60

50

40

30

20

10

-10
1 2 3 4
10 10 10 10
Frequency,Hz

6. Ocean Depth Measurements

1000

800
Ocean Depth, m

600

400

200

0
6
4
4
3
2 2
1
Y-axis, Km 0 0
X-axis, Km
Ocean Depth Measurements

-200
Ocean Depth, m

-400

-600

-800

-1000
6
4
4
3
2 2
1
Y-axis, Km 0 0
X-axis, Km

Pada gambar mesh(x,y,z) kurva kedalaman laut mengahadap keatas, hal ini dikarenakan
sumbu z nya bernilai positif. Kemudian untuk mesh(x,y,-z), kurva kedalaman laut
menghadap ke bawah dikarenakan z bernilai negative, hal ini sesuai dengan ketetapan
sumbu.
7. xi = linspace(0,4,30) ; % finer x-axis
yi = linspace(0,6,40) ; % finer y-axis
[xxi,yyi] = meshgrid(xi,yi) ; % grid of all combinations of xi and yi
zzi = interp2(x,y,z,xxi,yyi,'cubic'); % interpolate
mesh(xxi,yyi,zzi) % plot smoothed data
hold on
[xx,yy] = meshgrid(x,y); % grid original data
plot3 (xx,yy,z+0.1,'ok') % plot original data up a bit to show nodos
hold off
zmax=max(max(zzi))
zmax = 974.2315
[i.j]=find((zmax==zzi))
i = j: 291
xmzx=xi(j)
xmzx = 0.9655
ymax=yi(j)
ymax = 1.0769
xi(20)
ans = 2.6207
yi(20)
ans = 2.9231

Das könnte Ihnen auch gefallen