ENGR 516 Assignment 1 DuongLe
ENGR 516 Assignment 1 DuongLe
ENGR 516 Assignment 1 DuongLe
Assignment#1
Name: DUONG LE
Due: 02/18/2013
( )
( )
))
XK+1 = xK f(xK)/f(xK)
XK+1= xK [tan(pi-x) x] / [-2 tan2(pi-x)]
(1)
For the first area (from - /2 to /2): To find the root, let x0 = 1, the condition is |f(x)| < 10-10
Using Matlab to obtain these following data
With x0=1
K
x
1
1
2
0.422122506263781
3
0.0264103193380855
4
6.14172788135359e-06
5
2.11419423634673e-18
f(x) meet the condition when x = 2.11419423634673e-18 0
|f(x)|
2.55740772465490
0.871243263107487
0.0528267808328284
1.22834557629346e-05
1.24578874151082e-16
With x0=-1
K
x
1
-1
2
-0.422122506263781
3
-0.026410319338086
4
-6.141727881506243e-06
5
-2.009068977263002e-16
f(x) meet the condition when x = -2.009068977263002e-16 0
|f(x)|
2.55740772465490
0.871243263107486
0.0528267808328282
1.22834557628423e-05
7.84422178115649e-17
For the second area (from /2 to 3/2): To find the root, let x0 = 3, the condition is |f(x)| < 10-10
With x0=3
K
x
1
3
2
1.58564279909040
3
1.60013441776625
4
1.62805477384048
5
1.67968726477802
6
1.76685216638210
..
..
11
2.02875783811043
f(x) meet the condition when x = 2.0287
|f(x)|
2.85745345692572
65.7654764727369
32.4754663652182
15.8175269586881
7.46748768365328
3.26821548564776
..
1.56050861122026e-09
With x0=-3
K
x
1
-3
2
-1.58564279909040
3
-1.60013441776625
4
-1.62805477384048
5
-1.67968726477802
6
-1.76685216638210
..
..
11
-2.02875783785528
f(x) meet the condition when x = -2.0287
|f(x)|
2.85745345692572
65.7654764727380
32.4754663652187
15.8175269586883
7.46748768365342
3.268215485647831
..
1.56050949939868e-09
Matlab code (Change the value of x(1) at line 3 to 1 and 3 for each case of x0)
clear;
clc;
x(1)= 1;
Epsilon = 10^(-10);
k=1;
delta(k) = abs(tan(pi-x(k))-x(k));
while(true)
k= k+1;
x(k) = x(k-1) - (tan(pi-x(k-1))-x(k-1))/(-2 - (tan(pi-x(k-1)))^2);
delta(k) = abs(tan(pi-x(k))-x(k));
if delta(k)< Epsilon
break;
end
end
(
(
)
)
Let =10-10
For the first area (from - /2 to /2): choose two initial values of x(1) = -1.5 and x(2) =1
k
1
2
3
4
5
.
110
x
-1.5
1
0.647911229337960
0.470479978993301
0.354126331991277
.
4.173476495865219e-11
In the first area, the roots is approximately 0
f(x)
15.601419947171696
-0.557407724700000
-1.404824955284764
-0.979049851103723
-0.723838055822700
.
-8.346950318662128e-11
x
2
3
2.06081849450047
2.03032146541832
2.02883519360745
..
2.02875783811157
f(x)
0.185039863261518
-2.857453457
-0.186111258588269
-0.00953763433657784
-0.00047303316844793
..
-6.96642743491793e-12
f(x)
2.857453457
-0.185039863261520
0.186111258588268
0.00953763433657962
0.000473033168448822
..
6.96775970254748e-12
Matlab code (change the value of x(1) and x(2) at line 3 and 4 for desired initial numbers)
clear;
clc;
x(1) = -1.5;
x(2) = 1;
Epsilon = 10^(-10);
f(1) = tan(pi-x(1))-x(1);
f(2) = tan(pi-x(2))-x(2);
if f(1)*f(2) > 0
break;
end;
for k=2:1000
x(k+1)= (f(2)*x(1)- f(1)*x(2))/(f(2)-f(1));
f(k+1) = tan(pi-x(k+1))-x(k+1);
if f(k+1)==0,
break;
elseif f(2)*f(k+1)>0
x(2)=x(k+1);
f(2)=f(k+1);
else
x(1)=x(k+1);
f(1)=f(k+1);
end
if abs(f(k+1))<Epsilon,
break,
end
end
XK+1 = xK f(xK)/f(xK)
Let =10-10
K
1
2
3
4
5
6
7
x
10
18.3333333333333
15.1426426426426
13.9604605349711
13.7898198718246
13.7863959715875
13.7863959715875
|f(x)|
5
15.7407407407408
3.40511975669093
0.382882379195851
2.94165558756276e-06
8.76683055349542e-08
4.68070027181966e-13
(
(
)
)
Let =10-10
Choose two initial values of x(1) = 10 and x(2) =20
K
1
2
3
4
5
..
36
x
10
20
11.666666666666666
12.694805194805193
13.252086742951052
..
13.786394606985908
f(x)
-5
25
-3.518518518518519
-2.064644012590549
-1.081422715779407
..
-5.632116995002434e-11
1
0
3.9
2
0.8
3.5
3
1.5
2.7
4
2.5
2.2
5
4.0
1.8
6
5.0
1.5
7
5.8
0
I use the following equation from the book (equation 9 page 823 from the book):
(
( )
Where
) and
( ) and
With j = 1, 2, 3, 4, 5, 6
The matrix form of above equation is: A.K=B
With A is the coefficient matrix of K and B is the matrix of right hand side
Note: With the normal Cubic Spline method:
A(1, 2:7)= 0 and A(1,1)=1 .
At j=7, A(7, 2:6)=0 and A(7,7)=1, B(1) = 0 and B(7) = 0.
Using Matlab to get the result of A, B and K
Matrix A:
j=1
j=2
j=3
j=4
j=5
j=6
j=7
1
1.2500
0
0
0
0
0
0
5.3571
1.4286
0
0
0
0
0
1.4286
4.8571
1
0
0
0
0
0
1
3.3333
0.6667
0
0
0
0
0
0.6667
3.3333
1
0
0
0
0
0
1
4.50000
0
0
0
0
0
0
1.25000
1
Matrix B:
j=1
j=2
j=3
j=4
j=5
j=6
j=7
0
-6.7730
-6.3980
-2.0333
-1.4333
-7.9313
0
Matrix K:
j=1
0
j=2
-1.0124
j=3
-0.9447
j=4
-0.3633
j=5
0.1837
j=6
-1.8033
j=7
0
The cubic polynomial form (equation 12 page 823 from the book):
( )
j=1
j=2
j=3
j=4
j=5
j=6
3.9000
3.5000
2.7000
2.2000
1.8000
1.5000
-1.5265e-15
-1.0124
-0.9447
-0.3633
0.1837
-1.8033
-0.6095
-0.6559
0.7527
-0.1713
0.5360
-2.5230
-0.0193
0.6708
-0.3080
0.1572
-1.0197
3.0417
3.5
2.5
1.5
0.5
Repeat the same process for the left hand side of graph:
Data point of the left hand side is:
i
xj
fj
1
-5.8
0
2
-5.0
1.5
3
-4.0
2.8
4
-2.5
2.2
5
6
-1.5 -0.8
2.7 3.5
7
0
3.9
j=1
j=2
j=3
j=4
j=5
j=6
0
1.5000
1.8000
2.2000
2.7000
3.5000
1.2096e-15
1.8033
-0.1837
0.3633
0.9447
1.0124
4.7771
-2.5230
0.5360
-0.1713
0.7527
-0.6559
-3.0417
1.0197
-0.1572
0.3080
-0.6708
0.0193
3.5
2.5
1.5
0.5
0
-6
-5
-4
-3
-2
-1
-4
-2
Entire graph
4
3.5
2.5
1.5
0.5
0
-6
Matlab code
(Change the X and Y value (at line 3 and 4) to calculate right hand side and left hand side)
clear;
clc;
X= [0 0.8 1.5 2.5 4 5 5.8];
Y= [3.9 3.5 2.7 2.2 1.8 1.5 0];
%X= [-5.8 -5.0 -4.0 -2.5 -1.5 -0.8 0];
%Y= [0 1.5 1.8 2.2 2.7 3.5 3.9];
n= length(X); K=zeros(n,1);
A= zeros(n);
B= zeros(n,1);
h= zeros(n-1,1);
c= zeros(n-1,1);
para= zeros(n-1,4);
for k=1:(n-1)
h(k)= X(k+1)-X(k);
end
c= 1./h;
A(1,1)= 1;
A(1,2)= 0;
B(1)= 0;
A(n,n-1)= 0;
A(n,n)= 1;
B(n)= 0;
for i=2:(n-1)
A(i,i-1)= c(i-1);
A(i,i)= 2*(c(i-1) + c(i));
A(i,i+1)= c(i);
B(i)= 3*(c(i-1)^2*(Y(i)-Y(i-1))+ c(i)^2*(Y(i+1)-Y(i)));
end
K= pinv(A)*B;
para(:,1)= Y(1:n-1)';
para(:,2)= K(1:n-1);
for j=1:(n-1)
para(j,3)= 3*(Y(j+1)-Y(j))/h(j)^2 - (K(j+1)+2*K(j))/h(j);
para(j,4)= 2*(Y(j)-Y(j+1))/h(j)^3 + (K(j+1)+K(j))/h(j)^2;
end
plot(X,Y,'r*');
hold on;
for k=1:(n-1)
x1= X(k):0.05:X(k+1);
n1= length(x1);
y1= zeros(4,n1);
y1(1,:)= 1;
y1(2,:)= (x1-X(k))';
y1(3,:)= ((x1-X(k)).*(x1-X(k)))';
y1(4,:)= ((x1-X(k)).*(x1-X(k)).*(x1-X(k)))';
y1plot= para(k,:)*y1;
plot(x1,y1plot);
end
The Clausius-Clapeyron Equation for transitions between a gas and a condensed phase:
With:
10
x 10
Pressure (Pa)
8
7
6
5
4
3
2
280
285
290
295
300
Temperature (K)
305
310
315
2.5
x 10
Pressure (Pa)
1.5
0.5
0
280
300
320
340
Temperature (K)
360
380
400
II. Polynomial t:
a/ The temperature range 283 K to 311 K in 2 K increments:
In this temperature range, NH3 is in compressible liquid or vapor state.
With equation:
P(T) = P0 + T (1)
Using the temperature-vapor pressure data for ammonia (NH3), I have: P(273) = 435083 and
P(283) = 622893.7
Solving equation (1) => P0 = -4692149.11 and = 18781.07
So: P(T) = -4692149.11 + 18781.07 T
MATLAB CODE:
T= 283:2:311;
P= -4692149.11 + 18781.07.*T;
c = polyfit(T,P,3);
f = polyval(c,T);
figure;
plot(T, f);
xlabel('Temperature (K)');
ylabel('Pressure (Pa)');
title('The Relationship between Temperature and Pressure');
12
x 10
11
Pressure (Pa)
10
6
280
285
290
295
300
Temperature (K)
305
310
315
2.6
x 10
2.4
2.2
Pressure (Pa)
2
1.8
1.6
1.4
1.2
1
0.8
0.6
280
300
320
340
Temperature (K)
360
380
400
Using the temperature-vapor pressure data for ammonia (NH3), I have: P(273) = 435083 and
P(283) = 622893.7
= (ln(622893.7) ln(435028))/ (283-273) = 0.035897
So: P(T) = Po x e0.035897(T-T0) with P0=622893.7 Pa and T0 = 283K
MATLAB CODE:
clear;
clc;
T= 283:2:311;
P= 622893*exp(0.035897.*(T-283));
figure;
plot(T, P);
xlabel('Temperature (K)');
ylabel('Pressure (Pa)');
title('The Relationship between Temperature and Pressure');
6
1.8
x 10
1.6
Pressure (Pa)
1.4
1.2
0.8
0.6
280
285
290
295
300
Temperature (K)
305
310
315
2.5
x 10
Pressure (Pa)
1.5
0.5
0
280
300
320
340
Temperature (K)
360
380
400
1.6
x 10
1.5
1.4
Pressure (Pa)
1.3
1.2
1.1
1
0.9
0.8
0.7
0.6
280
285
290
295
300
Temperature (K)
305
310
315
15
x 10
Pressure (Pa)
10
0
280
300
320
340
Temperature (K)
360
380
400