ENGR 516 Assignment 1 DuongLe

download ENGR 516 Assignment 1 DuongLe

If you can't read please download the document

Transcript of ENGR 516 Assignment 1 DuongLe

ENGR 516 Computational Methods for Graduate Students Assignment#1 Name: DUONG LE Due: 02/18/2013

PROBLEM 2: Solution by Iteration:1/ f(x) = tan(pi - x) - x = 0

a/ Solve by Newton Raphson Method:

( )

( ( )

) ( ( )) ( )

XK+1 = xK f(xK)/f(xK) XK+1= xK [tan(pi-x) x] / [-2 tan2(pi-x)] The condition of equation (1) is x /2 +k2 There are 2 separate areas. One is from - /2 to + /2, the other one is from /2 to 3/2 (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

Result: f(x) has 3 roots: 0, 2.0287

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

b/ Solve by Regula-Falsi Method: ( ) ( ) 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 ( ( ) )

For the second area (from /2 to 3/2): Choose two initial values of x(1) = 2 and x(2) = 3 k 1 2 3 4 5 .. 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

Choose two initial values of x(1) = -3 and x(2) = -2 k x 1 -3 2 -2 3 -2.06081849450047 4 -2.03032146541832 5 -2.02883519360745 .. .. 11 -2.02875783811157 In the second area, the roots are 2.0287 f(x) 2.857453457 -0.185039863261520 0.186111258588268 0.00953763433657962 0.000473033168448822 .. 6.96775970254748e-12

Result: f(x) has 3 roots: 0, 2.0287

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)) 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) = (1/125)*(x(k+1)*x(k+1) -25)*(x(k+1)-10) -5; 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)) C = 4.598 x 1013 P = 4.598x1013 x e-1371200 / 287.04T MATLAB CODE:clear; clc; T= 283:2:311; P= 4.598*10^13*exp((-1371200/287.04)./T); figure; plot(T, P); xlabel('Temperature (K)'); ylabel('Pressure (Pa)'); title('The relationship between temperature and pressure');

10 9 8 7 6 5 4 3

x 10

6

The relationship between temperature and pressure

Pressure (Pa)

2 280

285

290

295 300 Temperature (K)

305

310

315

b/ The temperature range 283 K to 388 K in 2 K increments: Similar to part a, the only change is the range of temperature is from 283K to 388K MATLAB CODE:clear; clc; T= 283:2:388; P= 4.598*10^13*exp((-1371200/287.04)./T); figure; plot(T, P); xlabel('Temperature (K)'); ylabel('Pressure (Pa)'); title('The relationship between temperature and pressure');

2.5

x 10

8

The relationship between temperature and pressure

2

Pressure (Pa)

1.5

1

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

5

The Relationship between Temperature and Pressure

11

10Pressure (Pa)

9

8

7

6 280

285

290

295 300 Temperature (K)

305

310

315

b/ The temperature range 283 K to 388 K in 2 K increments: Similar to part a, the only change is the range of temperature is from 283K to 388K MATLAB CODE:T= 283:2:388; 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');

2.6 2.4 2.2 2Pressure (Pa)

x 10

6

The Relationship between Temperature and Pressure

1.8 1.6 1.4 1.2 1 0.8 0.6 280

300

320

340 Temperature (K)

360

380

400

III. Exponential power Equation: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 x eT => = (ln(P(T) ln(P0))/T

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');1.8 x 106

The Relationship between Temperature and Pressure

1.6

1.4Pressure (Pa)

1.2

1

0.8

0.6 280

285

290

295 300 Temperature (K)

305

310

315

b/ The temperature range 283 K to 388 K in 2 K increments: Similar to part a, the only change is the range of temperature is from 283K to 388K MATLAB CODE:clear; clc; T= 283:10:388; P= 622893*exp(0.035897.*(T-283)); figure; plot(T, P); xlabel('Temperature (K)'); ylabel('Pressure (Pa)'); title('The Relationship between Temperature and Pressure');

2.5

x 10

7

The Relationship between Temperature and Pressure

2

Pressure (Pa)

1.5

1

0.5

0 280

300

320

340 Temperature (K)

360

380

400

IV. Log curve ts: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 x T => = ln(P)/ ln(T) Using the temperature-vapor pressure data for ammonia (NH3), I have: P(273) = 435083 and P(283) = 622893.7 = (ln(622893.7) ln(435028))/ (ln283-ln273) = 9.97816 So: P(T) = P0 x T9.97816 with P0= 2.1384377e-19 Pa MATLAB CODE:clear; clc; T = 283:2:311; P = 2.134377*10^(-19).*(T.^(9.97816)); figure; plot(T, P); xlabel('Temperature (K)'); ylabel('Pressure (Pa)'); title('The Relationship between Temperature and Pressure');

1.6 1.5 1.4 1.3Pressure (Pa)

x 10

6

The Relationship between Temperature and Pressure

1.2 1.1 1 0.9 0.8 0.7 0.6 280

285

290

295 300 Temperature (K)

305

310

315

b/ The temperature range 283 K to 388 K in 2 K increments: Similar to part a, the only change is the range of temperature is from 283K to 388K MATLAB CODE:clear; clc; T = 283:2:388; P = 2.134377*10^(-19).*(T.^(9.97816)); figure; plot(T, P); xlabel('Temperature (K)'); ylabel('Pressure (Pa)'); title('The Relationship between Temperature and Pressure');

15

x 10

6

The Relationship between Temperature and Pressure

10Pressure (Pa)

5

0 280

300

320

340 Temperature (K)

360

380

400