SELAMAT DATANG

23 06 matlab

function yr=linier(xr)
x=[1 2 3 4 5 6 7 ];
y=[0.5 2.5 2.0 4.0 3.5 6.0 5.5];
n= length (x);
sg_xy=0;
sg_x=0;
sg_y=0;
sg_x2=0;
for i=1:n
    sg_xy=sg_xy+x(i)*y(i);
    sg_x=sg_x+x(i);
    sg_y=sg_y+y(i);
    sg_x2=sg_x2+x(i)^2;
end
m=(n*sg_xy-(sg_x*sg_y))/(n*sg_x2-sg_x^2);
c=(sg_y/n)-(m*sg_x)/n;
fprintf('y=%7.4f x + %7.4f \n',m,c);
yr=m*xr+c;
fprintf('xr=%7.4f \n',xr)
fprintf('yr=%7.4f \n',yr)
hold on
plot(x,y,'o')
xg=linspace(0,8);
yg=m*xg+c;
plot(xg,yg)



function yr=xplinier(xr)
x=[1 2 3 4 5 ];
y=[0.5 1.7 3.4 5.7 8.4];
n= length (x);
sg_xy=0;
sg_x=0;
sg_y=0;
sg_x2=0;
for i=1:n
    sg_xy=sg_xy+x(i)*log(y(i));
    sg_x=sg_x+x(i);
    sg_y=sg_y+log(y(i));
    sg_x2=sg_x2+x(i)^2;
end
m=(n*sg_xy-(sg_x*sg_y))/(n*sg_x2-sg_x^2);
c=(sg_y/n)-(m*sg_x)/n;
fprintf('y=e^ %7.4f x + %7.4f \n',m,c);
yr=exp(m*xr+c);
fprintf('xr=%7.4f \n',xr)
fprintf('yr=%7.4f \n',yr)
hold on
plot(x,y,'o')
xg=linspace(0,5.5);
yg=exp(m*xg+c);
plot(xg,yg)

0 komentar:

Posting Komentar

Flag Counter