Академический Документы
Профессиональный Документы
Культура Документы
Jawaban:
Matlab Code:
Linier Regresi
Linear Saturasi
%saturasi
function [a, r2] = linsat(x,y)
% linregr: linear regression curve fitting
% [a, r2] = linregr(x,y): Least squares fit of straight
% line to data by solving the normal equations
% input: x = independent variable; y = dependent variable
% output: a = vector of slope, a(1), and intercept, a(2); r2 = coefficient of
determination
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
x = x(:); y = y(:); % convert to column vectors
sx=sum(1./x);
sy=sum(1./y);
sx2=sum((1./x).*(1./x));
sxy=sum((1./x).*(1./y));
sy2=sum((1./y).*(1./y));
b=1/a(2);
yp=b*(x/((b*a(1))+x));
plot(x,y,'o',x,yp);
grid on
Linear Power
%power
function [a, r2] = linlog(x,y)
n = length(x);
if length (y)~=n, error ('x and y must be same length'); end;
x=x(:); y=y(:);
sx=sum(log10(x));
sy=sum(log10(y));
sx2=sum(log10(x).*log10(x));
sxy=sum(log10(x).*log10(y));
sy2=sum(log10(y).*log10(y));
b=10.^(a(2));
yp=b.*(x.^(a(1)));
plot(x,y,'o',x,yp,'r')
grid on
Linear exponensial
%eksponensial
function [b, a, r2] = linexp(x,y)
% linregr: linear regression curve fitting
% [a, r2] = linregr(x,y): Least squares fit of straight
% line to data by solving the normal equations
% input: x = independent variable; y = dependent variable
% output: a = vector of slope, a(1), and intercept, a(2); r2 = coefficient of
determination
n = length(x);
sx=sum(x);
sy=sum(log(y));
sx2=sum(x.*x);
sxy=sum(x.*log(y));
sy2=sum(log(y).*log(y));
b=exp(a(2));
yp=b*exp(a(1).*x);
plot(x,y,'o',x,yp)
grid on
Command Window:
>> x=[2 3 4 5 6 7];
>> y=[0.5 0.333 0.25 0.2 0.1667 0.1429];
>> plot(x,y)
>> linregr
Error using linregr (line 7)
Not enough input arguments.
a=
-0.0667 0.5656
r2 =
0.8760
>> linsat
Error using linsat (line 8)
Not enough input arguments.
a=
-13.1256 7.9845
r2 =
0.8767
>>linlog
Error using linlog (line 3)
Not enough input arguments.
a=
-0.9995 -0.0004
r2 =
1.0000
>> linexp
Error using linexp (line 8)
Not enough input arguments.
b=
0.7260
a=
-0.2446 -0.3202
r2 =
0.9675
a) Hasil Persamaan:
𝑦 = 10−0.0004 𝑥 −0.9995
Y= 0,999𝑥 −0.9995
X= 4,3
b) Nilai R kuadra:
linear saturasi power eksponensial
R^2 0.8760 0.8767 1.0000 0.9675
c) Y=0.23, x?
Linear: 𝑦 = −0.0667 + 0.5656x
0,23 = -0.0667 + 0.565x
X= 5.031
Power: Y= 0,999𝑥 −0.9995
X= 4,3
0.5
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7
1. Jawaban:
Matlab Code:
Linier Regresi
Linear Saturasi
%saturasi
function [a, r2] = linsat(x,y)
% linregr: linear regression curve fitting
% [a, r2] = linregr(x,y): Least squares fit of straight
% line to data by solving the normal equations
% input: x = independent variable; y = dependent variable
% output: a = vector of slope, a(1), and intercept, a(2); r2 = coefficient of
determination
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
x = x(:); y = y(:); % convert to column vectors
sx=sum(1./x);
sy=sum(1./y);
sx2=sum((1./x).*(1./x));
sxy=sum((1./x).*(1./y));
sy2=sum((1./y).*(1./y));
b=1/a(2);
yp=b*(x/((b*a(1))+x));
plot(x,y,'o',x,yp);
grid on
Linear Power
%power
function [a, r2] = linlog(x,y)
n = length(x);
if length (y)~=n, error ('x and y must be same length'); end;
x=x(:); y=y(:);
sx=sum(log10(x));
sy=sum(log10(y));
sx2=sum(log10(x).*log10(x));
sxy=sum(log10(x).*log10(y));
sy2=sum(log10(y).*log10(y));
b=10.^(a(2));
yp=b.*(x.^(a(1)));
plot(x,y,'o',x,yp,'r')
grid on
Linear exponensial
%eksponensial
function [b, a, r2] = linexp(x,y)
% linregr: linear regression curve fitting
% [a, r2] = linregr(x,y): Least squares fit of straight
% line to data by solving the normal equations
% input: x = independent variable; y = dependent variable
% output: a = vector of slope, a(1), and intercept, a(2); r2 = coefficient of
determination
n = length(x);
sx=sum(x);
sy=sum(log(y));
sx2=sum(x.*x);
sxy=sum(x.*log(y));
sy2=sum(log(y).*log(y));
b=exp(a(2));
yp=b*exp(a(1).*x);
plot(x,y,'o',x,yp)
grid on
Command Window:
>> x=[1 2 3 4 5];
>> y=[0.5 0.8 0.9 0.941176 0.961538];
>> plot(x,y)
0.95
0.9
0.85
0.8
0.75
0.7
0.65
0.6
0.55
0.5
1 1.5 2 2.5 3 3.5 4 4.5 5
>> linregr
Error using linregr (line 7)
Not enough input arguments.
a=
0.1064 0.5013
r2 =
0.7870
>> linsat
Error using linsat (line 8)
Not enough input arguments.
>> [a, r2] = linsat(x,y)
a=
1.2290 0.7315
r2 =
0.9752
>> linlog
Error using linlog (line 3)
Not enough input arguments.
a=
0.4062 -0.2663
r2 =
0.9036
>> linexp
Error using linexp (line 8)
Not enough input arguments.
b=
0.5141
a=
0.1470 -0.6654
r2 =
0.7329
1.4
1.2
0.8
0.6
0.4
0.2
0
1 1.5 2 2.5 3 3.5 4 4.5 5
4.jawaban:
Matlab Code:
Eksplisit
function U=eksplisit(a,b,c,d,f,e1,e2,m,n)
%U=eksplisit(0.05,9,1.4129E-5,20,100,25,4,6)
%a panjang total
%b waktu total
%f konstanta
c=1.4129*10^-5;
h=a/(n-1); %delta x
k=b/(m-1); %delta t
r=c*k/h^2; %lambda, c=alpha
s=k/h;
T=zeros(n,m);
T(1,1:m)=e1; %batas kiri
T(n,1:m)=e2 %batas kanan
T(2:n-1,1)=d %batas di tengah
for j=2:m
for i=2:n-1
T(i,j)=r*(T(i+1, j-1)-2*T(i,j-1)+T(i-1,j-1))+T(i,j-1)-
f*k*(T(i,j-1));
%perhitungan finite difference dari penurunan deret taylor-nya
end
end
U=T';
figure(1)
surf(U)
xlabel('t')
ylabel('x')
zlabel('U')
figure(2)
xx=(0:0.01:0.05);
y1=U(2,1:n)
y2=U(3,1:n)
y3=U(4,1:n);
plot(xx,y1)
hold on
plot(xx,y2)
hold on
plot(xx,y3)
%axis (0:0.001:0.05)
xlabel('panjang (m)')
ylabel('temperatur (t)')
legend('Time: 3s' , 'Time: 6s', 'Time: 9s')
Command window:
>> eksplisit
Error using eksplisit (line 7)
Not enough input arguments.
>> U=eksplisit(0.05,9,1.4129E-5,30,100,30,4,6)
Error using eksplisit (line 7)
Not enough input arguments.
>> U=eksplisit(0.05,9,1.4129E-5,30,0.5,100,30,4,6)
T=
T=
y1 =
y2 =
U=
Kurva
100
Time: 3s
Time: 6s
80 Time: 9s
60
temperatur (t)
40
20
-20
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
panjang (m)
Matlab Code:
Implisit
function
U=implisit(panjang,waktu,lamda,suhutengah,suhuawal1,suhuawal2,t,l);
%U=eksplisit(0.05 ,9,1.4129E-5,20,100,25,4,6)
U=zeros(t,1);
R=zeros(l,l);
h=panjang/(l-1);
k=waktu/(t-1);
r=lamda*k/(h^2)
s1=1+2*r;
x=1-(0.5*k);
R(1,1)=1;
R(l,l)=1;
T(2:l-1,1)=suhutengah;
T(1,1)=suhuawal1;
T(l,1)=suhuawal2;
v=T';
U(1,1:l)=v;
for j=2:t
for i=2:l-1
R(i,i-1)=-1*r/(1-0.5*k);
R(i,i)=s1/(1-0.5*k);
R(i,i+1)=(-1*r)/(1-0.5*k);
end
T=R\T;
v=T';
U(j,1:l)=v;
end
figure(1)
surf(U)
xlabel('t')
ylabel('x')
zlabel('U')
end
Command window:
>> implisit
Error using implisit (line 4)
Not enough input arguments.
>> U=implisit(0.05,9,1.4129E-5,30,100,30,4,6)
r=
0.4239
>> implisit
Error using implisit (line 4)
Not enough input arguments.
>> U=implisit(0.05,9,1.4129E-5,30,100,30,4,6)
r=
0.4239
U=
100
80
60
40
U
20
-20
4
6
3
5
4
2 3
2
x 1 1
t
3.jawaban: