You are on page 1of 16

Sec 51

85-220 Numerical Analysis of Engineering Systems


Winter 2014
Tutorial 9
1. Using the following data, calculate the work done by stretching a spring that has a spring
constant of k = 300 N/m to xn = 0.35 m. Compute the work
xn

W Fdx
0
a) Using trapz function
b) Using quad function. To do this, first fit the data with a second order polynomial and
then integrate the polynomial numerically to compute the work:

F×103 N 0 0.01 0.028 0.046 0.063 0.11 0.13


x, m 0 0.05 0.10 0.15 0.20 0.30 0.35

Solution:
clear,clc
x=[0 0.05 0.10 0.15 0.20 0.30 0.35];
F=[0 0.01 0.028 0.046 0.063 0.11 0.13]*1e3;
plot(x,F, 'db')
p=polyfit(x,F,2)
y_fit=force(p,x)
hold on
plot(x,y_fit)
%Part a
W1=trapz(x,F)
W2=quad(@(x)force(p,x),0,0.35)
%Answers:
%W1 = 20.4250 N.m
%W2 = 20.2904 N.m

With function
function y=force(p,x)
y=polyval(p,x);

2. The heat convection is described by the Newton’s law

( )

where t =time, T=temperature of the body, Ta=temperature of the surrounding medium,


and h= heat convection coefficient. The following data has been measured for a metal
ball with initial temperature of 80 C, which has been dropped into water with constant
temperature of Ta=20 C. The temperature of the ball changes with time as
Time, min 0 6 12 18 24 30
, C 80 44.5 30 24.1 21.7 20.7

Determine the heat convection coefficient h by using linear regression. Use backward
finite difference to calculate the derivative.

Solution: h=0.2418 min-1


t=[0 6 12 18 24 30];
T=[80 44.5 30 24.1 21.7 20.7];
y=diff(T)./diff(t);
x=T-20;
as a result of the differentiation the length of y is shorter by one compared to the length of
x, so in order to make the lengths equal
xn=x(2:6); (backward difference)
a=polyfit(xn,y,1)
a=
-0.2418 0.0061
3. The enthalpy of a real gas is a function of pressure as described bellow

∫( ( ))

Using the following data estimate the enthalpy of the fluid at T=400K and P=50atm
(evaluate the integral from 0.1 to 50atm). Use centered finite difference to estimate the
value of the derivative.
P, atm V,L
T=340K T=400K T=460K
0.1 220 250 282.5
5 4.1 4.7 5.23
10 2.2 2.5 2.7
20 1.35 1.49 1.55
25 1.1 1.2 1.24
30 0.9 0.99 1.03
40 0.68 0.75 0.78
45 0.61 0.675 0.7
50 0.54 0.6 0.62

Solution: H=132.8 atm.L


T=[340 400 460];
P=[0.1 5 10 20 25 30 40 45 50];
V=[220 250 282.5; 4.1 4.7 5.23;2.2 2.5 2.7;1.35 1.49
1.55;1.1 1.2 1.24;0.9 0.99 1.03;0.68 0.75 0.78;0.61 0.675
0.7;0.54 0.6 0.62];
dVdT=(V(1:n,3)-V(1:n,1))/(T(3)-T(1));
y=V(1:n,2)-T(2)*dVdT;
trapz(P,y)
ans =
132.8033

4. Evaluate the vertical distance traveled by a rocket in the interval t=[0,40s] if the vertical
velocity varies as

( )
{ ( )
Use the adaptive quadrature (quad function) with tolerance 10-9
Solution:
clear,clc
S=quad(@(t)Vel(t),0,40,1e-9)
% Ans S = 4.3373e+004
With function
function v=Vel(t)
if t>=0
if t<10
v=11*t.^2-5*t;
elseif t<20
v=1100-5*t;
elseif t<30
v=50*t+2*(t-20).^2;
elseif t<=40
v=1700-10*(t-30);
end
end
Sec 52
85-220 Numerical Analysis of Engineering Systems
Winter 2014
Tutorial 9
1. If a capacitor initially holds no charge, the voltage across it as a function of time can be
computed as
t
1
V (t ) I (t )dt
C0

Calculate the integral with the value of C = 10−5 farad


c) Using trapz function
d) Using quad function. To do this, first fit the data with a fifth-order polynomial and
then integrate the polynomial numerically to compute the voltage:

t, s 0 0.2 0.4 0.6 0.8 1.0 1.2


I × 10-3, A 0.2 0.3683 0.3819 0.2282 0.0486 0.0082 0.1441

Solution:
clear,clc
t=[0 0.2 0.4 0.6 0.8 1.0 1.2];
I=[0.2 0.3683 0.3819 0.2282 0.0486 0.0082 0.1441]*1e-3;
C=1e-5;
y=I/C
plot(t,y, 'db')
p=polyfit(t,y,5)
y_fit=current(p,t)
hold on
plot(t,y_fit)
%Part a
V1=trapz(t,y)
V2=quad(@(x)current(p,x),0,1.2)
% V1 = 24.1450
% V2 = 24.1372

With function
function y=current(p,x)
y=polyval(p,x);

2. The heat convection is described by the Newton’s law

( )
where t =time, T=temperature of the body, Ta=temperature of the surrounding medium,
and h= heat convection coefficient. The following data has been measured for a metal
ball with initial temperature of 80 C, which has been dropped into water with constant
temperature of Ta=20 C. The temperature of the ball changes with time as
Time, min 0 6 12 18 24 30
, C 80 44.5 30 24.1 21.7 20.7

Determine the heat convection coefficient h by using linear regression. Use forward
finite difference to calculate the derivative.

Solution: h=0.0987 %min-1


clear,clc
t=[0 6 12 18 24 30];
T=[80 44.5 30 24.1 21.7 20.7];
y=diff(T)./diff(t);
x=T-20;
%as a result of the differentiation the length of y is shorter by one
%compared to the length of x, so in order to make the lengths equal
xn=x(1:5); %(forward difference)
a=polyfit(xn,y,1)
%a = -0.0987 0.0025

3. The enthalpy of a real gas is a function of pressure as described bellow

∫( ( ))

Using the following data estimate the enthalpy of the fluid at T=400K and P=50atm
(evaluate the integral from 0.1 to 50atm). Use centered finite difference to estimate the
value of the derivative.
P, atm V,L
T=340K T=400K T=460K
0.1 220 250 282.5
5 4.1 4.7 5.23
10 2.2 2.5 2.7
20 1.35 1.49 1.55
25 1.1 1.2 1.24
30 0.9 0.99 1.03
40 0.68 0.75 0.78
45 0.61 0.675 0.7
50 0.54 0.6 0.62

Solution: H=132.8 atm.L


T=[340 400 460];
P=[0.1 5 10 20 25 30 40 45 50];
V=[220 250 282.5; 4.1 4.7 5.23;2.2 2.5 2.7;1.35 1.49
1.55;1.1 1.2 1.24;0.9 0.99 1.03;0.68 0.75 0.78;0.61 0.675
0.7;0.54 0.6 0.62];
dVdT=(V(1:n,3)-V(1:n,1))/(T(3)-T(1));
y=V(1:n,2)-T(2)*dVdT;
trapz(P,y)
ans =
132.8033

4. The work done on an object is equal to the force times the distance moved in the
direction of the force. The velocity of an object in the direction of a force is given by

( )
( )
{

where v is in m/s. Determine the work if a constant force of 200 N is applied for all t.
Use the adaptive quadrature (quad function) with tolerance 10-9
Solution:
F=200 %N
Work=quad(@(t)work(t,F),0,40,1e-9)
% Ans Work = 1.2667e+006

With function
function w=work(t,F)
if t>=0
if t<5
v=4.*t;
elseif t<15
v=20+(5-t).^2;
elseif t<25
v=5.*t+2.*(t-2)+19;
elseif t<=40
v=65+t.^2./5;
end
end
w=F*v;
Sec 53
85-220 Numerical Analysis of Engineering Systems
Winter 2014
Tutorial 9
5. Using the following data, calculate the work done by stretching a spring that has a spring
constant of k = 300 N/m to xn = 0.35 m. Compute the work
xn

W Fdx
0
e) Using trapz function
f) Using quad function. To do this, first fit the data with a second order polynomial and
then integrate the polynomial numerically to compute the work:

F×103 N 0 0.01 0.028 0.046 0.063 0.11 0.13


x, m 0 0.05 0.10 0.15 0.20 0.30 0.35

Solution:
clear,clc
x=[0 0.05 0.10 0.15 0.20 0.30 0.35];
F=[0 0.01 0.028 0.046 0.063 0.11 0.13]*1e3;
plot(x,F, 'db')
p=polyfit(x,F,2)
y_fit=force(p,x)
hold on
plot(x,y_fit)
%Part a
W1=trapz(x,F)
W2=quad(@(x)force(p,x),0,0.35)
%Answers:
%W1 = 20.4250 N.m
%W2 = 20.2904 N.m

With function
function y=force(p,x)
y=polyval(p,x);

6. The heat convection is described by the Newton’s law

( )

where t =time, T=temperature of the body, Ta=temperature of the surrounding medium,


and h= heat convection coefficient. The following data has been measured for a metal
ball with initial temperature of 80 C, which has been dropped into water with constant
temperature of Ta=20 C. The temperature of the ball changes with time as
Time, min 0 6 12 18 24 30
, C 80 44.5 30 24.1 21.7 20.7

Determine the heat convection coefficient h by using linear regression. Use backward
finite difference to calculate the derivative.

Solution: h=0.2418 min-1


t=[0 6 12 18 24 30];
T=[80 44.5 30 24.1 21.7 20.7];
y=diff(T)./diff(t);
x=T-20;
as a result of the differentiation the length of y is shorter by one compared to the length of
x, so in order to make the lengths equal
xn=x(2:6); (backward difference)
a=polyfit(xn,y,1)
a=
-0.2418 0.0061
7. The enthalpy of a real gas is a function of pressure as described bellow

∫( ( ))

Using the following data estimate the enthalpy of the fluid at T=400K and P=50atm
(evaluate the integral from 0.1 to 50atm). Use centered finite difference to estimate the
value of the derivative.
P, atm V,L
T=340K T=400K T=460K
0.1 220 250 282.5
5 4.1 4.7 5.23
10 2.2 2.5 2.7
20 1.35 1.49 1.55
25 1.1 1.2 1.24
30 0.9 0.99 1.03
40 0.68 0.75 0.78
45 0.61 0.675 0.7
50 0.54 0.6 0.62

Solution: H=132.8 atm.L


T=[340 400 460];
P=[0.1 5 10 20 25 30 40 45 50];
V=[220 250 282.5; 4.1 4.7 5.23;2.2 2.5 2.7;1.35 1.49
1.55;1.1 1.2 1.24;0.9 0.99 1.03;0.68 0.75 0.78;0.61 0.675
0.7;0.54 0.6 0.62];
dVdT=(V(1:n,3)-V(1:n,1))/(T(3)-T(1));
y=V(1:n,2)-T(2)*dVdT;
trapz(P,y)
ans =
132.8033

8. Evaluate the vertical distance traveled by a rocket in the interval t=[0,40s] if the vertical
velocity varies as

( )
{ ( )
Use the adaptive quadrature (quad function) with tolerance 10-9
Solution:
clear,clc
S=quad(@(t)Vel(t),0,40,1e-9)
% Ans S = 4.3373e+004
With function
function v=Vel(t)
if t>=0
if t<10
v=11*t.^2-5*t;
elseif t<20
v=1100-5*t;
elseif t<30
v=50*t+2*(t-20).^2;
elseif t<=40
v=1700-10*(t-30);
end
end
Sec 54
85-220 Numerical Analysis of Engineering Systems
Winter 2014
Tutorial 9
5. If a capacitor initially holds no charge, the voltage across it as a function of time can be
computed as
t
1
V (t ) I (t )dt
C0

Calculate the integral with the value of C = 10−5 farad


g) Using trapz function
h) Using quad function. To do this, first fit the data with a fifth-order polynomial and
then integrate the polynomial numerically to compute the voltage:

t, s 0 0.2 0.4 0.6 0.8 1.0 1.2


I × 10-3, A 0.2 0.3683 0.3819 0.2282 0.0486 0.0082 0.1441

Solution:
clear,clc
t=[0 0.2 0.4 0.6 0.8 1.0 1.2];
I=[0.2 0.3683 0.3819 0.2282 0.0486 0.0082 0.1441]*1e-3;
C=1e-5;
y=I/C
plot(t,y, 'db')
p=polyfit(t,y,5)
y_fit=current(p,t)
hold on
plot(t,y_fit)
%Part a
V1=trapz(t,y)
V2=quad(@(x)current(p,x),0,1.2)
% V1 = 24.1450
% V2 = 24.1372

With function
function y=current(p,x)
y=polyval(p,x);

6. The heat convection is described by the Newton’s law

( )
where t =time, T=temperature of the body, Ta=temperature of the surrounding medium,
and h= heat convection coefficient. The following data has been measured for a metal
ball with initial temperature of 80 C, which has been dropped into water with constant
temperature of Ta=20 C. The temperature of the ball changes with time as
Time, min 0 6 12 18 24 30
, C 80 44.5 30 24.1 21.7 20.7

Determine the heat convection coefficient h by using linear regression. Use forward
finite difference to calculate the derivative.

Solution: h=0.0987 %min-1


clear,clc
t=[0 6 12 18 24 30];
T=[80 44.5 30 24.1 21.7 20.7];
y=diff(T)./diff(t);
x=T-20;
%as a result of the differentiation the length of y is shorter by one
%compared to the length of x, so in order to make the lengths equal
xn=x(1:5); %(forward difference)
a=polyfit(xn,y,1)
%a = -0.0987 0.0025

7. The enthalpy of a real gas is a function of pressure as described bellow

∫( ( ))

Using the following data estimate the enthalpy of the fluid at T=400K and P=50atm
(evaluate the integral from 0.1 to 50atm). Use centered finite difference to estimate the
value of the derivative.
P, atm V,L
T=340K T=400K T=460K
0.1 220 250 282.5
5 4.1 4.7 5.23
10 2.2 2.5 2.7
20 1.35 1.49 1.55
25 1.1 1.2 1.24
30 0.9 0.99 1.03
40 0.68 0.75 0.78
45 0.61 0.675 0.7
50 0.54 0.6 0.62

Solution: H=132.8 atm.L


T=[340 400 460];
P=[0.1 5 10 20 25 30 40 45 50];
V=[220 250 282.5; 4.1 4.7 5.23;2.2 2.5 2.7;1.35 1.49
1.55;1.1 1.2 1.24;0.9 0.99 1.03;0.68 0.75 0.78;0.61 0.675
0.7;0.54 0.6 0.62];
dVdT=(V(1:n,3)-V(1:n,1))/(T(3)-T(1));
y=V(1:n,2)-T(2)*dVdT;
trapz(P,y)
ans =
132.8033

8. The work done on an object is equal to the force times the distance moved in the
direction of the force. The velocity of an object in the direction of a force is given by

( )
( )
{

where v is in m/s. Determine the work if a constant force of 200 N is applied for all t.
Use the adaptive quadrature (quad function) with tolerance 10-9
Solution:
F=200 %N
Work=quad(@(t)work(t,F),0,40,1e-9)
% Ans Work = 1.2667e+006

With function
function w=work(t,F)
if t>=0
if t<5
v=4.*t;
elseif t<15
v=20+(5-t).^2;
elseif t<25
v=5.*t+2.*(t-2)+19;
elseif t<=40
v=65+t.^2./5;
end
end
w=F*v;

You might also like