0% found this document useful (0 votes)
40 views

Script Matlab

The document describes a MATLAB script that performs polynomial regression to determine the coefficients of a polynomial function that fits a set of temperature and heat capacity data points. The script initializes matrices, fills them with temperature values and polynomial terms, and uses Gaussian elimination to solve for the polynomial coefficients that minimize the error between the polynomial function and the actual heat capacity data values.

Uploaded by

Aldi Reinaldi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Script Matlab

The document describes a MATLAB script that performs polynomial regression to determine the coefficients of a polynomial function that fits a set of temperature and heat capacity data points. The script initializes matrices, fills them with temperature values and polynomial terms, and uses Gaussian elimination to solve for the polynomial coefficients that minimize the error between the polynomial function and the actual heat capacity data values.

Uploaded by

Aldi Reinaldi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 61

Script matlab

function [V] = NewtonRaphson_Redlickwong( T, P,Pc, Tc, w)


error=0.0000001;
R=8314;
T=500;
P=101.33;
Pc=3797;
Tc=425.2;
w=0.1931;
a=(0.42747*R^2*Tc^2)/Pc;
b=(0.08664*R*Tc)/Pc;
s=0.48508+1.55171*w-0.15613*w^2
alfa=(1+s*(1-(T/Tc)^0.5))^2
ii=1;
Vtebak=(R*T)/P;
V(1)=Vtebak;
while error <= 0.0000001
fungsi=(R*T*V(ii)^2)+(V(ii)*b*R*T)-(a*alfa*V(ii))-(b*a*alfa)-
(P*(V(ii)^3-(2*V(ii)^2*b)-(V(ii)*b^2)));
turunan=(2*R*T*V(ii))+(b*R*T)-(a*alfa)-(P*(3*V(ii)-(4*V(ii)*b)-b^2));
V(ii+1)=V(ii)-fungsi/turunan;
error=abs(V(ii+1)-V(ii))
ii=ii+1
end
V

COMMAND WINDOW

s=

0.7789

alfa =

0.8728

error =

26.8871

ii =

V=

1.0e+04 *

4.1024 4.1051
ans =

1.0e+04 *

4.1024 4.1051

>>
Flow Chart :
Mulai

R,T,P,Tc,Pc, error 10^-7

a = 0,42747*R^2*Tc^2/Pc

b = 0,08664*R*Tc/Pc

Vtebak = R*T/P

V(1) Vtebak

Ii 1

fungsi =( P*V^3)-(R*T*V^2)-((P*b^2)+(b*R*T)-a)*V-(a*b)

turunan = (3*P*V^2)-(2*R*T*V)-(P*b^2)-(b*R*T)+a

V(ii+1) = V(ii)-fungsi/turunan

Error=abs(V(ii+1)-V(ii))

Error=10^-7 ii ii+1

Selesai
3. function [a]=Regresi_Polinom(T,Cp,m)
T=[280 290 300 310 320 330 350 370 390 400]
Cp=[10,42779 10,71409 11.00599 11.30348 11.60654 11.91516 12,54899 13,20485
13,88262 14,22968]
n=10
m=3
Q=zeros(n,m+1)
P=zeros (m+1,n)
A=zeros(m+1,m+1)
c=zeros(m+1,1)
ii=1
while ii<=n
Q(ii,1)=1
ii=ii+1
end
ii=1
while ii<=n
jj=2
while jj<=m+1
Q(ii,jj)=T(ii)^(jj-1)
jj=jj+1
end
ii=ii+1
end
P=Q'
A=P*Q
k=1
while k<=m+1
sum=0
ii=1
while ii<=n
sum=sum+((T(ii)^(k-1))*Cp(ii))
ii=ii+1
end
c(k)=sum
k=k+1
end
x=eliminasi_gauss(A,c)
a=x

command window

>> no3

T=

280 290 300 310 320 330 350 370 390 400

Cp =

1.0e+04 *
Columns 1 through 12

0.0010 4.2779 0.0010 7.1409 0.0011 0.0011 0.0012 0.0012 0.0012 5.4899 0.0013
2.0485

Columns 13 through 16

0.0013 8.8262 0.0014 2.2968

n=

10

m=

Q=

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0
0 0 0 0

0 0 0 0

P=

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

A=

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

c=

ii =

1
Q=

1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

ii =

Q=

1 0 0 0

1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0
0 0 0 0

0 0 0 0

ii =

Q=

1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

ii =

Q=

1 0 0 0
1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

ii =

Q=

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

ii =
6

Q=

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

ii =

Q=

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0
1 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

ii =

Q=

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 0

0 0 0 0

ii =

Q=
1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 0

ii =

10

Q=

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0
ii =

11

ii =

jj =

Q=

1 280 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =
3

Q=

1 280 78400 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0
1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

ii =

jj =

Q=

1 280 78400 21952000

1 290 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0
1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000


1 290 84100 24389000

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

ii =

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 0 0
1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

4
Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

ii =

jj =

2
Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0
jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

ii =

5
jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 0
1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

5
ii =

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 0 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=
1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0
jj =

ii =

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 0 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =
3

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 0

1 0 0 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000


1 0 0 0

1 0 0 0

1 0 0 0

jj =

ii =

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 0 0

1 0 0 0
1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 0

1 0 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000


1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 0 0 0

1 0 0 0

jj =

ii =

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000


1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 390 0 0

1 0 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 390 152100 0

1 0 0 0

jj =

4
Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 390 152100 59319000

1 0 0 0

jj =

ii =

10

jj =

Q=
1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 390 152100 59319000

1 400 0 0

jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 390 152100 59319000

1 400 160000 0
jj =

Q=

1 280 78400 21952000

1 290 84100 24389000

1 300 90000 27000000

1 310 96100 29791000

1 320 102400 32768000

1 330 108900 35937000

1 350 122500 42875000

1 370 136900 50653000

1 390 152100 59319000

1 400 160000 64000000

jj =

ii =

11

P=
1 1 1 1 1 1 1 1 1 1

280 290 300 310 320 330 350 370 390 400

78400 84100 90000 96100 102400 108900 122500 136900 152100


160000

21952000 24389000 27000000 29791000 32768000 35937000 42875000 50653000


59319000 64000000

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0.0000 0.0000 0.0000 0.0000

0.0000 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

k=

sum =

ii =

1
sum =

10

ii =

sum =

42789

ii =

sum =

42799

ii =

4
sum =

114208

ii =

sum =

1.1422e+05

ii =

sum =

1.1423e+05

ii =

7
sum =

1.1424e+05

ii =

sum =

1.1425e+05

ii =

sum =

1.1427e+05

ii =

10

sum =
1.6916e+05

ii =

11

c=

1.0e+05 *

1.6916

k=

sum =

ii =
1

sum =

2800

ii =

sum =

12408710

ii =

sum =

12411710

ii =

4
sum =

34548500

ii =

sum =

3.4552e+07

ii =

sum =

3.4556e+07

ii =

7
sum =

3.4560e+07

ii =

sum =

3.4564e+07

ii =

sum =

3.4569e+07

ii =

10
sum =

5.6529e+07

ii =

11

c=

1.0e+07 *

0.0169

5.6529

k=

sum =

ii =
1

sum =

784000

ii =

sum =

3.5985e+09

ii =

sum =

3.5994e+09

ii =
4

sum =

1.0462e+10

ii =

sum =

1.0463e+10

ii =

sum =

1.0464e+10

ii =

7
sum =

1.0466e+10

ii =

sum =

1.0467e+10

ii =

sum =

1.0469e+10

ii =

10
sum =

1.9253e+10

ii =

11

c=

1.0e+10 *

0.0000

0.0057

1.9253

k=

sum =

0
ii =

sum =

219520000

ii =

sum =

1.0436e+12

ii =

sum =

1.0438e+12

ii =
4

sum =

3.1712e+12

ii =

sum =

3.1715e+12

ii =

sum =

3.1719e+12

ii =
7

sum =

3.1724e+12

ii =

sum =

3.1730e+12

ii =

sum =

3.1738e+12

ii =

10
sum =

6.6873e+12

ii =

11

c=

1.0e+12 *

0.0000

0.0001

0.0193

6.6873

k=

faktor =

-334
A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0.0000 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0.0000 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0.0000 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077


A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0.0000 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

c=

1.0e+12 *

0.0000

0.0000

0.0193

6.6873

faktor =

-113140

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000


0 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0048

0.0000 0.0000 0.0048 1.7077

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0004


0.0000 0.0000 0.0048 1.7077

c=

1.0e+12 *

0.0000

0.0000

0.0001

6.6873

faktor =

-38868400

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0004

0 0.0000 0.0048 1.7077

A=

1.0e+16 *
0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0004

0 0.0000 0.0048 1.7077

A=

1.0e+16 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0004

0 0.0000 0.0004 1.7077

A=

1.0e+15 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0038

0 0.0000 0.0038 1.9696

c=

1.0e+11 *
0.0000

0.0000

0.0011

1.1212

faktor =

-681.5909

A=

1.0e+15 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0 0.0000 0.0038

0 0.0000 0.0038 1.9696

A=

1.0e+15 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0 0.0000 0.0038

0 0.0000 0.0038 1.9696


A=

1.0e+15 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0 0.0000 0.0000

0 0.0000 0.0038 1.9696

c=

1.0e+11 *

0.0000

0.0000

0.0009

1.1212

faktor =

-3.5110e+05

A=

1.0e+15 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000


0 0 0.0000 0.0000

0 0 0.0038 1.9696

A=

1.0e+15 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0000

0 0 0.0000 0.0000

0 0 0.0000 1.9696

A=

1.0e+13 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0006

0 0 0.0000 0.0017

0 0 0.0017 1.7064

c=

1.0e+11 *

0.0000

0.0000

0.0009
1.0248

faktor =

-1.0166e+03

A=

1.0e+13 *

0.0000 0.0000 0.0000 0.0000

0 0.0000 0.0000 0.0006

0 0 0.0000 0.0017

0 0 0 1.7064

A=

1.0e+10 *

0.0000 0.0000 0.0001 0.0389

0 0.0000 0.0011 0.5561

0 0 0.0016 1.6769

0 0 0 1.6254

c=

1.0e+09 *
0.0002

0.0000

0.0949

6.0502

x=

1.0e+07 *

-1.3474 0.0123 -0.0000 0.0000

a=

1.0e+07 *

-1.3474 0.0123 -0.0000 0.0000

ans =

1.0e+07 *

-1.3474 0.0123 -0.0000 0.0000

>>

You might also like