# 9.2 Problem Set

- Page ID
- 9481

Let the function y defined by \(y=\cos (x)\) Plot this function over the interval [-pi,pi]. Use numerical integration techniques to estimate the integral of y over [0, pi/2] using increments of pi/10 and pi/1000.

**Answer:**-
1. Plotting x=-pi:pi/100:pi; y=cos(x); plot(x,y),title('Graph of y=cos(x)'),xlabel('x'),ylabel('y'),grid

2. Area calculation 1: >> x=0:pi/10:pi/2; >> y=cos(x); >> area1=trapz(x,y) area1 = 0.9918

3. Area calculation 2: >> x=0:pi/1000:pi/2; >> y=cos(x); >> area2=trapz(x,y) area2 = 1.0000

Let the function y defined b \(y=0.04 x^{2}-2.13 x+32.58\) Plot this function over the interval [3,30]. Use numerical integration techniques to estimate the integral of y over [3,30].

**Answer:**-
1. Plotting: >> x=3:.1:30; >> y=0.04*(x.^2)-2.13.*x+32.58; >> plot(x,y), title('Graph of ... y=.04*(x^2)-2.13*x+32.58'),xlabel('x'),ylabel('y'),grid

2. Area calculation: >> area=trapz(x,y) area = 290.3868

A 2000-liter tank is full of lube oil. It is known that if lube oil is drained from the tank, the mass flow rate will decrease from the maximum when the tank level is at the highest. The following data were collected when the tank was drained.

Time [min] |
Mass Flow [kg/min] |

0 | 50.00 |

5 | 48.25 |

10 | 46.00 |

15 | 42.50 |

20 | 37.50 |

25 | 37.50 |

30 | 19.00 |

35 | 9.00 |

Data

Write a script to estimate the amount of oil drained in 35 minutes.

**Answer:**-
clc t=linspace(0,35,8) % Data entry for time [min] m=[50 48.25 46 42.5 37.5 30.5 19 9] % Data entry for mass flow [kg/min] % Calculate time intervals dt=[t(2)-t(1),t(3)-t(2),t(4)-t(3),... t(5)-t(4),t(6)-t(5),t(7)-t(6),t(8)-t(7)] % Calculate mass out dm=[0.5*(m(2)+m(1)),0.5*(m(3)+m(2)),0.5*(m(4)+m(3)),0.5*(m(5)+... m(4)),0.5*(m(6)+m(5)),0.5*(m(7)+m(6)),0.5*(m(8)+m(7))] % Calculate differential areas da=dt.*dm; % Tabulate time and mass flow [t',m'] % Tabulate time intervals, mass out and differential areas [dt',dm',da'] % Calculate the amount of oil drained [kg] in 35 minutes Oil_Drained=sum(da)

The output is:

ans = 0 50.0000 5.0000 48.2500 10.0000 46.0000 15.0000 42.5000 20.0000 37.5000 25.0000 30.5000 30.0000 19.0000 35.0000 9.0000 ans = 5.0000 49.1250 245.6250 5.0000 47.1250 235.6250 5.0000 44.2500 221.2500 5.0000 40.0000 200.0000 5.0000 34.0000 170.0000 5.0000 24.7500 123.7500 5.0000 14.0000 70.0000 Oil_Drained = 1.2663e+003

A gas is expanded in an engine cylinder, following the law PV^{1.3}=c. The initial pressure is 2550 kPa and the final pressure is 210 kPa. If the volume at the end of expansion is 0.75 m^{3}, compute the work done by the gas. ^{1}

**Answer:**-
clc disp('A gas is expanded in an engine cylinder, following the law PV^1.3=c') disp('The initial pressure is 2550 kPa and the final pressure is 210 kPa.') disp('If the volume at the end of expansion is 0.75 m3,') disp('Compute the work done by the gas.') disp(' ') % Display blank line n=1.3; P_i=2550; % Initial pressure P_f=210; % Final pressure V_f=.75; % Final volume V_i=(P_f*(V_f^n)/P_i)^(1/n); % Initial volume c=P_f*V_f^n; v=V_i:.001:V_f; % Creating a row vector for volume, v p=c./(v.^n); % Computing pressure for volume WorkDone=trapz(v,p) % Integrating p*dv.

The output is:

A gas is expanded in an engine cylinder, following the law PV^1.3=c The initial pressure is 2550 kPa and the final pressure is 210 kPa. If the volume at the end of expansion is 0.75 m3, Compute the work done by the gas. WorkDone = 409.0666

A force F acting on a body at a distance s from a fixed point is given by \(F=3 s+\frac{1}{s^{2}}\) Write a script to compute the work done when the body moves from the position where s=1 to that where s=10. ^{2}

**Answer:**-
clc disp('A force F acting on a body at a distance s from a fixed point is given by') disp('F=3*s+(1/(s^2)) where s is the distance in meters') disp('Compute the total work done in moving') disp('From the position where s=1 to that where s=10.') disp(' ') % Display blank line s=1:.001:10; % Creating a row vector for distance, s F=3.*s+(1./(s.^2)); % Computing Force for s WorkDone=trapz(s,F) % Integrating F*ds over 1 to 10 meters.

The output is:

A force F acting on a body at a distance s from a fixed point is given by F=3*s+(1/(s^2)) where s is the distance in meters Compute the total work done in moving From the position where s=1 to that where s=10. WorkDone = 149.4000

The pressure p and volume v of a given mass of gas are connected by the relation \(\left(p+\frac{a}{v^{2}}\right)(v-b)=k\) where a, b and k are constants. Express p in terms of v, and write a script to compute the work done by the gas in expanding from an initial volume to a final volume. ^{3}

Test your solution with the following input:

a: 0.01

b: 0.001

The initial pressure [kPa]: 100

The initial volume [m3]: 1

The final volume [m3]: 2

**Answer:**-
clc % Clear screen disp('This script computes the work done by') disp('The gas in expanding from volume v1 to v2') disp(' ') % Display blank line a=input('Enter the constant a: '); b=input('Enter the constant b: '); p_i=input('Enter the initial pressure [kPa]: '); v_i=input('Enter the initial volume [m3]: '); v_f=input('Enter the final volume [m3]: '); k=(p_i+(a/(v_i^2))*(v_i-b)); % Calculating constant k v=v_i:.001:v_f; % Creating a row vector for volume p=(k./(v-b))-(a./(v.^2)); % Computing pressure for volume WorkDone=trapz(v,p); % Integrating p*dv disp(' ') % Display blank line str = ['The work done by the gas in expanding from ', num2str(v_i),... ' m3 to ' num2str(v_f), ' m3 is ', num2str(WorkDone), ' kW.']; disp(str); The output is: This script computes the work done by The gas in expanding from volume v1 to v2 Enter the constant a: .01 Enter the constant b: .001 Enter the initial pressure [kPa]: 100 Enter the initial volume [m3]: 1 Enter the final volume [m3]: 2 The work done by the gas in expanding from 1 m3 to 2 m3 is 69.3667 kW.