30
1 Chapter 3 Solved Problems 1. For the function , calculate the value of y for the following val- ues of x using element-by-element operations: . Solution >> x=1:7 x = 1 2 3 4 5 6 7 >> y=x.^2-x./(x+3) y = 0.7500 3.6000 8.5000 15.4286 24.3750 35.3333 48.3000 2. For the function , calculate the value of y for the following values of x using element-by-element operations: . Solution >> x=1.5:0.5:4 x = 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 >> y=x.^4.*exp(-x) y = 1.1296 2.1654 3.2064 4.0328 4.5315 4.6888 01234567 , , , , , , , 1.5 2 2.5 3 3.5 4 , , , , ,

Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

  • Upload
    others

  • View
    19

  • Download
    8

Embed Size (px)

Citation preview

Page 1: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

1

Chapter 3 Solved Problems

1. For the function , calculate the value of y for the following val-

ues of x using element-by-element operations: .

Solution

>> x=1:7x = 1 2 3 4 5 6 7>> y=x.^2-x./(x+3)y = 0.7500 3.6000 8.5000 15.4286 24.3750

35.3333 48.3000

2. For the function , calculate the value of y for the following values ofx using element-by-element operations: .

Solution>> x=1.5:0.5:4x = 1.5000 2.0000 2.5000 3.0000 3.5000

4.0000>> y=x.^4.*exp(-x)y = 1.1296 2.1654 3.2064 4.0328 4.5315

4.6888

0 1 2 3 4 5 6 7, , , , , , ,

1.5 2 2.5 3 3.5 4, , , , ,

Page 2: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

2 Chapter 3: Solved Problems

3. For the function , calculate the value of y forthe following values of x using element-by-element operations: –2, –1.5, –1,–0.5, 0, 0.5, 1, 1.5, 2.

Solution

>> x=-2:0.5:2x = -2.0000 -1.5000 -1.0000 -0.5000 0

0.5000 1.0000 1.5000 2.0000>> y=(x+x.*sqrt(x+3)).*(1+2*x.^2)-x.^3y = -28.0000 -14.9791 -6.2426 -1.8109 0

2.0281 8.0000 22.3759 50.2492

4. For the function , calculate the value of y for the following

values of x using element-by-element operations: .

Solution

>> x=15:10:65x = 15 25 35 45 55 65>> y=(4*sind(x)+6)./(cosd(x).^2+sind(x)).^2y = 4.9528 4.9694 5.3546 6.0589 7.0372

8.1775

5. The radius, r, of a sphere can be calculated from its volume, V, by:

The surface area of a sphere, S, is given by:

Determine the radius and surface area of spheres with volumes of 4,000,

3,500, 3,000, 2,500, 2,000, 1,500 and 1,000 in3. Display the results in a three-column table where the values of r, V, and S are displayed in the first, sec-ond, and third columns, respectively. The values of r and S that are dis-played in the table should be rounded to the nearest tenth of an inch.

Solution

15° 25° 35° 45° 55° 65°, , , , ,

S 4πr2=

Page 3: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 3

Script File:

V=4000:-500:1000;

r=(3/(4*pi)*V).^(1/3);

S=4*pi*r.^2;

Result(:,1)=round(r*10)/10;

Result(:,2)=V;Result(:,3)=round(S*10)/10

Command Window:Result = 9.80 4000.00 1218.60 9.40 3500.00 1114.80 8.90 3000.00 1005.90 8.40 2500.00 890.80 7.80 2000.00 767.70 7.10 1500.00 633.70 6.20 1000.00 483.60

6. A 70 lb bag of rice is being pulled by a personby applying a force F at an angle θ as shown.The force required to drag the bag is givenby:

where is the friction coefficient.(a) Determine for . (b) Determine the angle θ where F is minimum. Do it by creating a vector θ

with elements ranging from to and spacing of 0.01. Calculate Ffor each value of θ and then find the maximum F and associated θ withMATLAB’s built-in function max.

Solution

Script File:th=5:5:35; mu=0.35;% Part (a)F=70*mu./(mu*sind(th)+cosd(th))% Part (b)thb=5:0.01:35;Fb=70*mu./(mu*sind(thb)+cosd(thb));

μ 0.35=

F θ( ) θ 5° 10° 15° 20° 25° 30° 35°, , , , , ,=

5° 35°

Page 4: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

4 Chapter 3: Solved Problems

[Fm, i]=min(Fb);Fmin=Fb(i)at_Theta=thb(i)

Command Window:

F = 23.86 23.43 23.19 23.13

23.24 23.53 24.02Fmin = 23.12at_Theta = 19.29

7. The remaining loan balance, B, of a fixed payment n years mortgage after xyears is given by:

where L is the loan amount, and r is the annual interest rate. Calculate thebalance of a 30 year, $100,000 mortgage, with annual interest rate of 6%(use 0.06 in the equation) after 0, 5, 10, 15, 20, 25, and 30 years. Create aseven-element vector for x and use element-by-element operations. Displaythe results in a two-row table where the values of years, and balance are dis-played in the first and second rows, respectively.

Solution

Script File:L=100000; n=30; r=0.06;x=0:5:30;C=(1+r/12);B=L*(C^(12*n)-C.^(12*x))./(C^(12*n)-1);Table=[x;B]

Command Window:Table = 0 5.00 10.00

15.00 20.00 25.00 30.00 100000.00 93054.36 83685.72 71048.84

54003.59 31012.09 0

Page 5: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 5

8. The length (magnitude) of a vector is given by

. Given the vector , determine itslength by writing one MATLAB command in which the vector is multipliedby itself using element-by-element operation and the MATLAB built-infunctions sum and sqrt are used.

Solution

>> u=[-5.6 11 -14];>> Length=sqrt(sum(u.*u))Length = 18.6644

9. A unit vector un in the direction of the vector is given by

where is the length (magnitude) of the vector, given by

. Given the vector , determine the unit vec-tor in the direction of u using the following steps:(a) Assign the vector to a variable u. (b) Using element-by-element operation and the MATLAB built-in func-

tions sum and sqrt calculate the length of u and assign it to the vari-able Lu.

(c) Use the variables from Parts (a) and (b) to calculate un.(d) Verify that the length of un is 1 (same operations as in Part (b)).

Solution

>> % Part (a):u=[4 13 -7];% Part (b):Lu=sqrt(sum(u.*u))Lu = 15.2971>> % Part (c):un=u/Luun = 0.2615 0.8498 -0.4576>> %Part (d):Lun=sqrt(sum(un.*un))Lun = 1.0000

u

u x2 y2 z2+ +=

Page 6: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

6 Chapter 3: Solved Problems

10. The angle between two vectors and

can be determined by , where .

Given the vectors and , determinethe angle between them (in degrees) by writing one MATLAB commandthat uses element-by-element multiplication and the MATLAB built-infunctions acosd, sum and sqrt.

Solution

>> u1=[3.2 -6.8 9];>> u2=[-4 2 7];>> Theta=acosd(sum(u1.*u2)/

(sqrt(sum(u1.*u1))*sqrt(sum(u2.*u2))))Theta = 67.93

11. The following vector is defined in MATLAB: d=[2 4 3]

By hand (pencil and paper) write what will be displayed if the followingcommands are executed by MATLAB. Check your answers by executing thecommands with MATLAB.(a) d+d (b) d.^d (c) d.*d (d) d.^2

Solution

>> d=[2 4 3];>> d+dans = 4.00 8.00 6.00>> d.^dans = 4.00 256.00 27.00>> d.*dans = 4.00 16.00 9.00>> d.^2ans = 4.00 16.00 9.00

Page 7: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 7

12. The following two vectors are defined in MATLAB:v=[3 -1 2] , u=[6 4 -3]

By hand (pencil and paper) write what will be displayed if the followingcommands are executed by MATLAB. Check your answers by executing thecommands with MATLAB.(a) v.*u (b) v.^u (c) v*u’

Solution

>> v=[3 -1 2];>> u=[6 4 -3];>> v.*uans = 18 -4 -6>> v.^uans = 729.0000 1.0000 0.1250>> v*u'ans = 8

13. Define the vector . Then use the vector in a mathematicalexpression to create the following vectors:(a) (b)(c) (d)

Solution

>> v=[1 3 5 7];>> a=3*va = 3 9 15 21>> b=v.^2b = 1 9 25 49>> c=v./vc = 1 1 1 1>> d=6*v./vd = 6 6 6 6

Page 8: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

8 Chapter 3: Solved Problems

14. Define the vector . Then use the vector in a mathematicalexpression to create the following vectors:

(a) (b)

(c) (d)

Solution

>> v=[5 4 3 2];>> a=1./(v+v)a = 0.1000 0.1250 0.1667 0.2500>> b=v.^vb = 3125 256 27 4>> c=v./sqrt(v)c = 2.2361 2.0000 1.7321 1.4142>> d=v.^2./v.^vd = 0.0080 0.0625 0.3333 1.0000

15. Define x and y as the vectors and. Then use them in the following expressions to

calculate z using element-by-element calculations.

(a) (b)

Solution

>> x=0.5:0.5:2.5;>> y=0.8:0.8:4;>> % Part (a):>> z=x.^2+2*x.*yz = 1.0500 4.2000 9.4500 16.8000 26.2500>> % Part (b):>> z=x.*y.*exp(y./x)-(x.^4.*y.^3+8.5).^(1/3)z = -0.0622 5.5981 13.5494 23.5926 35.9429

Page 9: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 9

16. Define r and s as scalars and , and, t, x, and y as vectors, , and . Then

use these variables to calculate the following expressions using element-by-element calculations for the vectors.

(a) (b)

Solution

>> r=1.6E3; s=14.2;>> t=1:5;>> x=2:2:10;>> y=3:3:15;>> % Part (a):>> G=x.*t+r/s^2*(y.^2-x).*tG = 1.0e+03 * 0.0575 0.5158 1.8034 4.3486 8.5801>> % Part (b):>> R=r*(-x.*t+y.*t.^2)/15-s^2*(y-0.5*x.^2).*tR = 1.0e+04 * -0.0095 0.2513 1.2164 3.3198 6.9954

17. The area of a triangle ABC can be calculatedby , where rAB and rAC are vec-tors connecting the vertices A and B, and Aand C, respectively. Determine the area of thetriangle shown in the figure. Use the follow-ing steps in a script file to calculate the area.First, define the vectors rOA, rOB and rOC fromknowing the coordinates of points A, B, andC. Then determine the vectors rAB and rAC

from rOA, rOB and rOC. Finally, determine the area by using MATLAB’sbuilt-in functions cross, sum. and sqrt.

Solution

>> rOA=[8 5 -4];>> rOB=[-7 9 6];>> rOC=[-5 -2 11];>> rAB=rOB-rOA;

Page 10: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

10 Chapter 3: Solved Problems

>> rAC=rOC-rOA;>> Area=sqrt(sum(cross(rAB,rAC).^2))/2Area = 112.4433

18. The cross product of two vectors can be used fordetermining the angle between two vectors:

Use MATLAB’s built-in functions asind,cross, sqrt, and dot to find the angle (indegrees) between and

. Recall that .

Solution

>> r1=[2.5 8 -5];>> r2=[-1 6 3];>> r1CRr2=cross(r1,r2);>> r1CRr2L=sqrt(sum(r1CRr2.*r1CRr2));>> r1L=sqrt(sum(r1.*r1));>> r2L=sqrt(sum(r2.*r2));>> Theta=asind(r1CRr2L/(r1L*r2L))Theta = 62.5629

19. The center of mass, , of n particles canbe calculated by:

,

where xi, yi, and zi and mi are the coordinatesand the mass of particle i, respectively. The coordinates and mass of six par-ticles are listed in the following table. Calculate the center of mass of theparticles.

Particle Mass (kg)

Coordinate x(mm)

Coordinate y(mm)

Coordinate z(mm)

A 0.5 -10 8 32B 0.8 -18 6 19C 0.2 -7 11 2

Page 11: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 11

Solution

Script File:% P is a matrix with 6 rows and 4 columns.% A row for each particle.% Columns: mass, x, y, z coordinatesP=[0.5 -10 8 32; 0.8 -18 6 19; 0.2 -7 11 2 1.1 5 12 -9; 0.4 0 -8 -6; 0.9 25 -20 8];Mass=sum(P(:,1))x=sum(P(:,1).*P(:,2))/Massy=sum(P(:,1).*P(:,3))/Massz=sum(P(:,1).*P(:,4))/Mass

Command Window:

Mass = 3.9000x = 1.8462y = 0.7692z = 6.7949

20. Define the vectors:, , and

Use the vectors to verify the identity:

Use MATLAB’s built-in functions cross and dot, calculate the value ofthe left and right sides of the identity.

Solution

>> a=[7 -4 6];>> b=[-4 7 5];>> c=[5 -6 8];>> LHS=cross(a,cross(b,c))

D 1.1 5 12 -9E 0.4 0 -8 -6F 0.9 25 -20 8

Page 12: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

12 Chapter 3: Solved Problems

LHS = -298 593 743>> RHS=b*dot(a,c)-c*dot(a,b)RHS = -298 593 743

21. The maximum distance s and the maximumheight h that a projectile shot at an angle θare given by:

and

where v0 is the shooting velocity and

m/s2. Determine s(θ) for if m/s.

Solution

>> g=9.81; v0=260;>> th=15:10:75th = 15 25 35 45 55 65 75>> s=v0^2/g*sind(2*th)s = 1.0e+03 * 3.4455 5.2788 6.4754 6.8909 6.4754

5.2788 3.4455 >> h=v0^2*sind(th).^2/(2*g)h = 1.0e+03 * 0.2308 0.6154 1.1335 1.7227 2.3119

2.8301 3.2147

Page 13: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 13

22. Use MATLAB to show that the sum of the infinite series converges

to . Do this by computing the sum for:(a) , (b) , (c)For each part create a vector n in which the first element is 1, the incrementis 1 and the last term is 5, 50, or 5000. Then use element-by-element calcula-

tions to create a vector in which the elements are . Finally, use MAT-

LAB’s built-in function sum to sum the series. Compare the values to .Use format long to display the numbers.

Solution

Script File:

format long% Part (a)n=1:5;an=1./n.^2;Sa=sum(an)pi_sq_ov6=pi^2/6% Part (b)n=1:50;an=1./n.^2;Sb=sum(an)pi_sq_ov6=pi^2/6% Part (c)n=1:5000;an=1./n.^2;Sc=sum(an)pi_sq_ov6=pi^2/6

Command Window:

Sa = 1.463611111111111pi_sq_ov6 = 1.644934066848226Sb = 1.625132733621529pi_sq_ov6 =

1n2-----

n 1=

Page 14: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

14 Chapter 3: Solved Problems

1.644934066848226Sc = 1.644734086846901pi_sq_ov6 = 1.644934066848226

23. Use MATLAB to show that the sum of the infinite series converges

to 6. Do this by computing the sum for(a) , (b) , (c) For each part, create a vector n in which the first element is 1, the incrementis 1 and the last term is 5, 15 or 30. Then use element-by-element calcula-

tions to create a vector in which the elements are . Finally, use MAT-

LAB’s built-in function sum to sum the series. Use format long to displaythe numbers.

Solution

Script File:format long% Part (a)n=1:5;an=n.^2./2.^n;Sa=sum(an)% Part (b)n=1:15;an=n.^2./2.^n;Sb=sum(an)% Part (c)n=1:30;an=n.^2./2.^n;Sc=sum(an)

Command Window:

Sa = 4.406250000000000Sb = 5.991119384765625Sc = 5.999999044463038

n 1=

Page 15: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 15

24. The natural exponential function can be expressed by . Deter-

mine e2 by calculating the sum of the series for:(a) n = 5, (b) n = 15, (c) n = 25

For each part create a vector n in which the first element is 0, the incrementis 1, and the last term is 5, 15, or 25. Then use element-by-element calcula-

tions to create a vector in which the elements are . Finally, use the MAT-

LAB built-in function sum to add the terms of the series. Compare the

values obtained in parts (a), (b), and (c) with the value of e2 calculated byMATLAB.

Solution

Script File:

format long% Part (a)n=0:5;an=2.^n./factorial(n);Sa=sum(an)ePower2=exp(2)% Part (b)n=0:15;an=2.^n./factorial(n);Sb=sum(an)ePower2=exp(2)% Part (c)n=0:25;an=2.^n./factorial(n);Sc=sum(an)ePower2=exp(2)

Command Window:

Sa = 7.266666666666667ePower2 = 7.389056098930650Sb = 7.389056095384136ePower2 =

n 0=

Page 16: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

16 Chapter 3: Solved Problems

7.389056098930650Sc = 7.389056098930649ePower2 = 7.389056098930650

25. Show that . Do this by first creating a vector x that

has the elements , , , ,

, and . Then, create a new vector y in which each ele-

ment is determined from the elements of x by . Compare the ele-

ments of y with the value . Use format long to display the numbers.

Solution

Script File:

format longx=[pi/3-0.1 pi/3-0.01 pi/3-0.0001 pi/3+0.0001 pi/3+0.01 pi/3+0.1];Lim=sin(x-pi/3)./(4*cos(x).^2-1)CompareValue=sqrt(3)/6

Command Window:

Lim = Columns 1 through 4 -0.274238398404589 -0.287032331771222 -

0.288658470333254 -0.288691803667625 Columns 5 through 6 -0.290366054030767 -0.307964386863987CompareValue = 0.288675134594813

26. Show that . Do this by first creating a vector x that has

the elements 1.0, 0.1, 0.01, 0.001, and 0.0001. Then, create a new vector y in

which each element is determined from the elements of x by .

Page 17: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 17

Compare the elements of y with the value 7.5. Use format long to displaythe numbers.

Solution

Command Window:

>> x=[1 0.1 0.01 0.001 0.0001];>> y=5*sin(6*x)./(4*x)y = Columns 1 through 4 -0.349269372748657 7.058030917437943

7.495500809930575 7.499955000080999 Column 5 7.499999550000009

27. The Hazen Williams equation can be used to calculate the pressure drop, Pd(psi/ft of pipe) in pipes due to friction:

where Q is the flow rate (gpm), C is a design coefficient determined by thetype of pipe, and d is pipe diameter in inches. Consider a 3.5 in. diametersteel pipe with . Calculate the pressure drop in a 1000 ft long pipefor flow rates of 250, 300, 350, 400, and 450 gpm. To carry out the calcula-tion first create a five-element vector with the values of the flow rates (250,300, ....). Then use the vector in the formula using element-by-element oper-ations.

Solution

>> C=120; d=3.5;>> Q=250:50:450Q = 250 300 350 400 450>> Pd=4.52*Q.^1.85/(C^1.85*d^4.87)Pd = Columns 1 through 4 0.039375925047993 0.055171663010881

0.073378298262268 0.093940471923615 Column 5 0.116811312607597

Page 18: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

18 Chapter 3: Solved Problems

28. The monthly lease payment, Pmt, of a new car can be calculated by:

where Pv and Fv are the present value and the future value (at the end of thelease) of the car, respectively. N is the duration of the lease in months, and iis the interest rate per year. Consider a 36 months lease of a car with a pres-ent value of $38,000 and a future value of $23,400. Calculate the monthlypayments if the yearly interest rates are 3, 4, 5, 6, 7, and 8%. To carry out thecalculation first create a five-element vector with the values of the interestrates (0.03, 0.04, ....). Then use the vector in the formula using element-by-element operations.

Solution

>> i=0.03:0.01:0.08;>> Nu=38000-23400./(1+i/12).^36;>> De=(1-1./(1+(1+i./12).^36))./(i/12);>> Pmt=Nu./DePmt = 1.0e+02 * Columns 1 through 3 0.794879505046213 1.084572758996790

1.384345790655600 Columns 4 through 6 1.693006947249476 2.009471591203944

2.332753536801580

Page 19: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 19

29. Create the following three matrices:

(a) Calculate and to show that addition of matrices is commu-tative.

(b) Calculate A*(B*C) and (A*B)*C to show that multiplication of matricesis associative.

(c) Calculate 5(B+C) and 5B+5C to show that, when matrices are multi-plied by a scalar, the multiplication is distributive.

(d) Calculate (A+B)*C and A*C+B*C to show that matrix multiplication isdistributive.

Solution

Script File:

A=[5 -3 7; 1 0 -6; -4 8 9]B=[3 2 -1; 6 8 -7; 4 4 0]C=[-9 8 3; 1 7 -5; 3 3 6]ApB=A+BBpA=B+AAtBC=A*(B*C)ABtC=(A*B)*CBpC5=5*(B+C)B5pC5=5*B+5*CApBtC=(A+B)*CAtCpBtC=A*C+B*C

Command Window:

A = 5 -3 7 1 0 -6 -4 8 9B = 3 2 -1 6 8 -7 4 4 0C = -9 8 3

A B+ B A+

Page 20: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

20 Chapter 3: Solved Problems

1 7 -5 3 3 6ApB = 8 -1 6 7 8 -13 0 12 9BpA = 8 -1 6 7 8 -13 0 12 9AtBC = -163 346 101 164 -325 41 -712 1064 -556ABtC = -163 346 101 164 -325 41 -712 1064 -556BpC5 = -30 50 10 35 75 -60 35 35 30B5pC5 = -30 50 10 35 75 -60 35 35 30ApBtC = -55 75 65 -94 73 -97 39 111 -6AtCpBtC = -55 75 65 -94 73 -97 39 111 -6

Page 21: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 21

30. Use the matrices A, B, and C from the previous problem to answer the fol-lowing:

(a) Does A*B=B*A ? (b) Does (B*C)-1 = B-1*C-1?

(c) Does ? ( t means transpose) (d) Does (A + B)t = At + Bt?

Solution

Script File:

A=[5 -3 7; 1 0 -6; -4 8 9]B=[3 2 -1; 6 8 -7; 4 4 0]C=[-9 8 3; 1 7 -5; 3 3 6]AtB=A*BBtA=B*ABtCi=(B*C)^-1BitCi=B^-1*C^-1Ait=A^-1'Ati=A'^-1ApBt=(A+B)'AtpBt=A'+B'

Command Window:

A = 5 -3 7 1 0 -6 -4 8 9B = 3 2 -1 6 8 -7 4 4 0C = -9 8 3 1 7 -5 3 3 6AtB = 25 14 16 -21 -22 -1 72 92 -52BtA = 21 -17 0 66 -74 -69 24 -12 4BtCi = -0.1200 0.0053 0.0627

Page 22: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

22 Chapter 3: Solved Problems

-0.0571 0.0000 0.0500 0.0515 -0.0212 -0.0008BitCi = -0.0676 0.0433 0.0421 0.0737 -0.0607 -0.0180 0.0222 -0.0444 0.0074Ait = 0.1912 0.3307 0.0717 0.0598 0.2908 0.1474 0.0319 -0.1116 0.0120Ati = 0.1912 0.0598 0.0319 0.3307 0.2908 -0.1116 0.0717 0.1474 0.0120ApBt = 8 7 0 -1 8 12 6 -13 9AtpBt = 8 7 0 -1 8 12 6 -13 9

31. Create a matrix A having random integer values between 1 and 5. Callthe matrix A and, using MATLAB, perform the following operations. Foreach part explain the operation.

(a) A.^A (b) A.*A (c) A*A-1

(d) A./A (e) det(A) (f) inv(A)

Solution

>> A=randi(5,3)A = 1 3 4 5 1 2 3 5 3>> A.^Aans = 1 27 256 3125 1 4 27 3125 27>> A.*Aans =

Page 23: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 23

1 9 16 25 1 4 9 25 9>> A*A^-1ans = 1.0000 -0.0000 0.0000 -0.0000 1.0000 0.0000 0 -0.0000 1.0000>> A./Aans = 1 1 1 1 1 1 1 1 1>> det(A)ans = 54.0000>> inv(A)ans = -0.1296 0.2037 0.0370 -0.1667 -0.1667 0.3333 0.4074 0.0741 -0.2593

32. The magic square is an arrangement of numbers in a square grid in such away that the sum of the numbers in each row, and in each column, and ineach diagonal is the same. MATLAB has a built-in function magic(n)that returns an magic square. In a script file create a (5 5) magicsquare, and then test the properties of the resulting matrix by finding thesum of the elements in each row, in each column and in both diagonals. Ineach case, use MATLAB’s built-in function sum. (Other functions that canbe useful are diag and fliplr.)

Solution

Script File:

A=magic(5)AR1=sum(A(1,:))AR2=sum(A(2,:))AR3=sum(A(3,:))AR4=sum(A(4,:))AR5=sum(A(5,:))AC1=sum(A(:,1))AC2=sum(A(:,2))

Page 24: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

24 Chapter 3: Solved Problems

AC3=sum(A(:,3))AC4=sum(A(:,4))AC5=sum(A(:,5))DAR=sum(diag(A))DAL=sum(diag(fliplr(A)))

Command Window:A = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9AR1 = 65AR2 = 65AR3 = 65AR4 = 65AR5 = 65AC1 = 65AC2 = 65AC3 = 65AC4 = 65AC5 = 65DAR = 65DAL = 65

33. Solve the following system of three linear equations:

Solution

>> a=[-2 5 7; 3 -6 2; 9 -3 8];

Page 25: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 25

>> b=[-17.5; 40.6; 56.2];>> x=a\bx = 3.2000 -4.6000 1.7000

34. Solve the following system of six linear equations:

Solution

>> a=[2 -4 5 -3.5 1.8 4; -1.5 3 4 -1 -2 5; 5 1 -6 3 -2 21.2 -2 3 4 -1 4; 4 1 -2 -3 -4 1.5; 3 1 -1 4 -2 -4]a = 2.0000 -4.0000 5.0000 -3.5000 1.8000

4.0000 -1.5000 3.0000 4.0000 -1.0000 -2.0000

5.0000 5.0000 1.0000 -6.0000 3.0000 -2.0000

2.0000 1.2000 -2.0000 3.0000 4.0000 -1.0000

4.0000 4.0000 1.0000 -2.0000 -3.0000 -4.0000

1.5000 3.0000 1.0000 -1.0000 4.0000 -2.0000 -

4.0000>> b=[52.52;-21.1;-27.6;9.16;-17.9;-16.2]b = 52.5200 -21.1000 -27.6000 9.1600 -17.9000 -16.2000>> x=a\bx = 1.8000

Page 26: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

26 Chapter 3: Solved Problems

-6.2000 2.6000 -1.6000 4.4000 -0.6000

35. A football stadium has 100,000 seats. In a game with full capacity peoplewith the following ticket and associated cost attended the game:

Determine the number of people that attended the game in each cost cate-gory if the total revenue was $4,897,000, there were 11,000 more alumnithan faculty, the number of public plus alumni together was 10 times thenumber of veterans, the number of faculty plus alumni together was thesame as the number of students, and the number of faculty plus studentstogether was four times larger than the number of gusts and veteranstogether.

Solution

>> a=[1 1 1 1 1 1; 25 40 60 70 32 0; 0 -1 1 0 0 0; 0 1 0 1 -10 0-1 1 1 0 0 0; 1 0 1 0 -4 -4]a = 1 1 1 1 1 1 25 40 60 70 32 0 0 -1 1 0 0 0 0 1 0 1 -10 0 -1 1 1 0 0 0 1 0 1 0 -4 -4>> b=[100000; 4897000; -11000; 0; 0; 0]b = 100000 4897000 -11000 0 0

Student Alumni Faculty Public Veterans GuestsCost $25 $40 $60 $70 $32 $0

Page 27: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 27

0>> x=a\bx = 1.0e+04 * 2.500000000000000 1.800000000000000 0.700000000000000 4.200000000000000 0.600000000000000 0.200000000000000

Students: 25000, Alumni:18000, Faculty:7000, Public: 42000, Veterans: 6000, Guests: 2000

36. A food company manufactures five types of 8 oz Trail mix packages usingdifferent mixtures of peanuts, almonds, walnuts, raisins, and M&Ms. Themixtures have the following compositions:

How many packages of each mix can be manufactured if 105 lb of peanuts,74 lb of almonds, 102 lb of walnuts, 118 lb of raisins, and 121 lb of M&Msare available? Write a system of linear equations and solve.

Solution

>> a=[3 1 1 2 1; 1 2 1 0 2; 1 1 0 3 3; 2 3 3 1 0; 1 1 3 2 2]

a = 3 1 1 2 1 1 2 1 0 2 1 1 0 3 3 2 3 3 1 0

Peanuts (oz)

Almonds (oz)

Walnuts (oz)

Raisins (oz)

M&Ms (oz)

Mix 1 3 1 1 2 1Mix 2 1 2 1 3 1Mix 3 1 1 0 3 3Mix 4 2 0 3 1 2Mix 5 1 2 3 0 2

Page 28: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

28 Chapter 3: Solved Problems

1 1 3 2 2>> b=[105; 74; 102; 118; 121]*16b = 1680 1184 1632 1888 1936>> x=a\bx = 208.0000 176.0000 240.0000 224.0000 192.0000

Mix1: 208, Mix2: 176, Mix3: 240, Mix4: 224, Mix5: 192.

37. The electrical circuit shown consists ofresistors and voltage sources. Determine

and , using the mesh currentmethod based on Kirchhoff’s voltagelaw (see Sample Problem 3-4).

V, V, V,

Ω, Ω, ΩΩ, Ω, Ω,

Ω, Ω.

Solution

The four equations can be rewritten in matrix form [A][x] = [B]:

R1 R2

R3

R5R4

V1

V3

R6 R7

R8+ _

i1 i2 i3

i4

V2

+

+

_

_

Page 29: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

Chapter 3: Solved Problems 29

Script file:clear, clcV1=28; V2=36; V3=42;R1=16; R2=10; R3=6; R4=12;R5=8; R6=14; R7=4; R8=5;A=[-(R1+R3) R3 0 0 R3 -(R2+R3+R4+R6) R4 00 R4 -(R4+R5+R7) R70 R6 R7 -(R6+R7+R8)];B=[-V1; 0; V2; -V3];I=A\B

Command Window:

I = 1.2136 -0.2168 -1.3656 1.4566>>

Page 30: Chapter 3 Solved Problems Hydrodynamikk... · 2019. 12. 11. · Chapter 3: Solved Problems 5 8. The length (magnitude) of a vector is given by. Given the vector , determine its length

30 Chapter 3: Solved Problems