Uploaded by User30362

Topik5 170210102072 17092019

advertisement
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')
n = 2; p = polyfit(x,y,n)
p =
-9.8108
20.1293
-0.0317
xi = linspace(0,1,100);
yi = polyval(p,xi);
figure,plot(x,y,'-o',xi,yi,' :')
pp = polyfit(x,y,10) ;
z = polyval(pp,xi);
figure, plot(x,y,'o',xi,z,':' )
figure, plot(x,y,'o',xi,z,':' )
% One Dimensional Interpolation
yi = interp1(x,y,xi)
yi = interp1(x,y,xi)
interpolasi linier
interpolasi linier
|
{ Error: Unexpected MATLAB expression.
}
x1 = linspace(0 , 2*pi, 60);
x2 = linspace(0 , 2*pi, 6) ;
figure, plot(x1 , sin(x1) )
figure, plot(x2 , sin(x2) , '?')
{ Error using <a href="matlab:helpUtils.errorDocCallback('plot')"
style="font-weight:bold">plot</a>
Error in color/linetype argument
}
figure, plot(x2 , sin(x2) , '-')
figure, plot(x1 , sin(x1), x2 , sin(x2) , '-') ), grid on
figure, plot(x1 , sin(x1), x2 , sin(x2) , '-') ), grid on
|
{ Error: Unbalanced or unexpected parenthesis or bracket.
}
figure, plot(x1 , sin(x1), x2 , sin(x2),'-'),grid on
xlabel('x'), ylabel('Sin(x)') , title('Linear Interpolation')
% Sound Pressure Level Data M-File sound.m
sound
s = interp1(Hz,spl,2.5e3)
s =
-5.5000
s = interp1(Hz,spl,2.5e3,'linear')
s =
-5.5000
s = interp1(Hz,spl,2.5e3,'spline')
s =
-5.8690
s = interp1(Hz,spl,2.5e3,'cubic')
s =
-6.0488
s = interp1(Hz,spl,2.5e3,'nearest')
s =
-8
% Two-Dimensional Interpolation
ocean
zi = interp2(x,y,z,2.2,3.3)
zi =
103.9200
zi = interp2(x,y,z,2.2,3.3,'linear')
zi =
103.9200
zi = interp2(x,y,z,2.2,3.3,'cubic')
zi =
104.1861
zi = interp2(x,y,z,2.2,3.3,'spline')
zi =
104.3016
zi = interp2(x,y,z,2.2,3.3,'nearest')
zi =
102
xi = linspace(0,4,30) ;
yi = linspace(0,6,40) ;
[xxi,yyi] = meshgrid(xi,yi) ;
of xi and yi
zzi = interp2(x,y,z,xxi,yyi,'cubic');
mesh(xxi,yyi,zzi)
hold on
[xx,yy] = meshgrid(x,y);
plot3 (xx,yy,z+0.1,'ok')
bit to show nodos
hold off
zmax = max(max(zzi))
zmax =
108.0520
% finer x-axis
% finer y-axis
% grid of all combinations
% interpolate
% plot smoothed data
% grid original data
% plot original data up a
[i,j] = find(zmax == zzi)
i =
20
j =
20
xmzx = xi(j)
xmzx =
2.6207
ymax = yi(i)
ymax =
2.9231
xi(20)
ans =
2.6207
yi(20)
ans =
2.9231
diary off
Download