Anda di halaman 1dari 20

Number of Qs = 82 =82= 21 (level 1) + 21 (level 2) + 20 (level 3) + 20 (level 4) (Question 1)What is the output of the following MATLAB expression?

(a) A=[1 3; 4 5]; (b) C=eye(2)-A./A (c) The value of C(2,2) is Solution: (b) C=[0,-1;-1,0] (c) C(2,2)=0 Multiple choice (Answers in bold): Choice 1) 1 Choice 2) -1

Choice 3) 0

Choice 4) 2

(Question 2)Use the linspace function to create vectors identical to the colon notation t = 4:6:34 and select the correct answer(s) Solution: t = linspace(4,34,6); Multiple choice (Answers in bold): Choice 1) t = linspace(4,6,34); Choice 2) t = linspace(34,4,6);

Choice 3) t = linspace(4,34,6);

Choice 4) None

(Question 3)Use colon notation to create vectors identical to the following created with the linspace function The value of r = linspace (8,4.5,8); is identical to Solution: r= [8, 7.5, 7, 6.5, 6, 5.5, 5, 4.5] Multiple choice (Answers in bold): Choice 1) r = 8 : .5 : 4.5; Choice 2) r = 8 : 4.5 : 8;

Choice 3) r = 8 : -0.5 : 4.5;

Choice 4) r = 8 : 0.5 : 4.5;

(Question 4)The following matrix is entered in MATLAB: A=[3 2 1;0:0.5:1;linspace(6, 8, 3)]; (a) Write out the resulting matrix. (b) If we use colon notation to write a single-line MATLAB command to multiply the second row by the third column and assign the result to the variable C, the value of C would be same as Solution: (a) A=[3, 2, 1;0, 0.5, 1; 6, 7, 8] (b) C = A(2,:)*A(:,3); C = 8.5; Multiple choice (Answers in bold): Choice 1) C = A(:,3)*A(2,:); Choice 2) C = A(2,:)*A(:,3);

Choice 3) C = a(2,:)*A(:,3);

Choice 4) C = 8.5;

(Question 5)The density of freshwater can be computed as a function of temperature with the following cubic equation rho = 5.5289E-8 Tc^3 - 8.5016E-6 Tc^2 + 6.5622E-5 Tc + 0.99987 where rho = density (g/cm^3) and Tc = temperature (degree Celsius). Write a MATLAB code (a) to generate a vector of temperatures ranging from 32 degrees Fahrenheit to 93.2 degrees Fahrenheit using increments of 3.6 degrees Fahrenheit (b)to convert this vector to degrees Celsius (c)to compute a vector of densities based on the cubic formula (d)to create a plot of rho versus Tc. Recall that Tc = (5/9)*(Tf - 32) (e)The value of rho(10) is closest to Solution: a) Tf=32:3.6:93.2; b) Tc=5*(Tf-32)/9; c) rho=5.5289*1e-8*Tc.^3 - 8.5016*1e-6*Tc.^2 + 6.5622*1e-5*.Tc + 0.99987; d) plot(rho, Tc);

e) 0.9986 Multiple choice (Answers in bold): Choice 1) 1.0000 Choice 2) 2.0000

Choice 3) 0.9986

Choice 4) 0.9944

(Question 6)An example of computer hardware is Solution: An example of computer hardware is computer chips Multiple choice (Answers in bold): Choice 1) computer Choice 2) MS chips Word

Choice 3) A computer program with a series of instructions

Choice 4) All of the above

(Question 7)ASCII number for the character a=97, d=100, e=101, D=68, then what is the ASCII number for the character A? Solution: The ASCII number for the character A is 65 Multiple choice (Answers in bold): Choice 1) 97 Choice 2) 66 (Question 8)How many bits does 1101 have? Solution: 1101 has 4 bits Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2

Choice 3) 65

Choice 4) 98

Choice 3) 0

Choice 4) 4

(Question 9)How many items can be represented by 3 bits binary number? Solution: 8 items can be represented by 3 bits Multiple choice (Answers in bold): Choice 1) 3 Choice 2) 9 (Question 10)64 bits equals Solution: 64 bits equals 8 bytes Multiple choice (Answers in bold): Choice 1) 1 byte Choice 2) 8 bytes (Question 11)How many bytes does a 1TB hard disk have Solution: A 1TB hard disk has more than 1000 billion bytes Multiple choice (Answers in bold): Choice 1) 1 trillion Choice 2) greater than 1000 billion

Choice 3) 8

Choice 4) 1

Choice 3) 3 bytes

Choice 4) None

Choice 3) 1 billion

Choice 4) less than 1 trillion

(Question 12)The value of the binary number 01001 in decimal is Solution: The value of the binary number 01001 in decimal is 9 Multiple choice (Answers in bold): Choice 1) 11 Choice 2) 1001 (Question 13)The value of the binary number 111 in decimal is Solution: The value of the binary number 111 in decimal is 1*2^2 + 1*2^1 + 1*2^0 = 7

Choice 3) 9

Choice 4) 10

Multiple choice (Answers in bold): Choice 1) 111 Choice 2) 5

Choice 3) 7

Choice 4) None

(Question 14)The value of the decimal number 10 in binary is Solution: The value of the decimal number 10 in binary is 1010 which is equal to 01010 Multiple choice (Answers in bold): Choice 1) 10 Choice 2) 110

Choice 3) 1010

Choice 4) 01010

(Question 15)If b=1; what is value of a at the end of following operations b=b+1; a = b + 1; Solution: If b=1 b=b+1 b=1+1=2 a=b+1 b=2+1=3 Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2 (Question 16)If b=1; b=b+1; a =2*b + 1; What is the value of c if c=a+b? Solution: b=1 b=b+1 = 1+1 = 2 a=2*b + 1 = 2*2 + 1 = 5 c=a+b = 5 + 2=7 Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 7 (Question 17)If x=2; y= x^2 + 2*x + 10=? Solution: y= x^2 + 2*x + 10 y= 2^2 + 2*2 +10 y= 4 + 4 + 10 y= 18 Multiple choice (Answers in bold): Choice 1) 8 Choice 2) 18 (Question 18)If f= inline('x^2 + 2*x + 10'); f(2) = ? Solution: f = inline('x^2 + 2*x + 10') f = inline('2^2 + 2*2 + 10')=18 Multiple choice (Answers in bold): Choice 1) 18 Choice 2) 100

Choice 3) 3

Choice 4) 4

Choice 3) 11

Choice 4) 3

Choice 3) 20

Choice 4) 10

Choice 3) 10

Choice 4) 4

(Question 19)If f(x)= x^2 + 2*x ; g(y) = 2*y; then f(1) * g(2) = ?

Solution: f(x)= x^2 + 2*x f(1)=1^2 + 2*1=3 g(y) = 2*y g(2)=2*2=4 f(1)*g(2)=3*4=12 Multiple choice (Answers in bold): Choice 1) 18 Choice 2) 12

Choice 3) 3

Choice 4) None

(Question 20)A MATLAB code to compute magnitude of a vector v is given by: mag_v=0; for i=1:length(v); mag_v=mag_v + v(i)^2; end; mag_v=sqrt(mag_v); If v=[3 4]; what is the value of mag_v? Solution: mag_v = 5 Multiple choice (Answers in bold): Choice 1) 3 Choice 2) 5

Choice 3) 4

Choice 4) 7

(Question 21)If a=3, the MATLAB output to the last line b=a*4 is identical to Solution: a=3 b=a*4=3*4=12 Multiple choice (Answers in bold): Choice 1) 3+3+3+3 Choice 2) 3*3*3*3 (Question 22)Which one is an illegal variable name? Solution: 1dog is an illegal variable name Multiple choice (Answers in bold): Choice 1) dog1 Choice 2) under_dog

Choice 3) 16

Choice 4) 12

Choice 3) underdog

Choice 4) 1dog

(Question 23)In MATLAB,floor(1.3) - round(1.4) gives an output of Solution: floor(1.3) - round(1.4) = 1 - 1 = 0 Multiple choice (Answers in bold): Choice 1) -1 Choice 2) 0

Choice 3) -.1

Choice 4) .1

(Question 24)To calculate the value of cosine of 90 degrees, the correct MATLAB expression is Solution: The correct MATLAB expression for the value of cosine of 90 degrees is cos(pi/2) Multiple choice (Answers in bold): Choice 1) cos(Pi/2) Choice 2) cos(90)

Choice 3) Cos(pi/2)

Choice 4) cos(pi/2)

(Question 25)3^2^2 in MATLAB will give Solution: ans = 3^2^2=81 Multiple choice (Answers in bold): Choice 1) 27 Choice 2) 81

Choice 3) 12

Choice 4) 64

(Question 26)Consider that xr is the only root for the function, f(x) = 0. If x is less than than xr, then the value |f(x) - f (xr)|is Solution: The value |f(x) - f(xr)|is always greater than 0 Multiple choice (Answers in bold): Choice 1) 0 Choice 2) Greater than 0

Choice 3) Less than 0

Choice 4) None

(Question 27)If xr1 and xr2 are the two roots for the function, f(x) = 0, then the value |f(xr1) - f(xr2)|is Solution: The value |f(xr1) - f(xr2)|is 0 Multiple choice (Answers in bold): Choice 1) 0 Choice 2) greater than 0

Choice 3) less than 0

Choice 4) None

(Question 28)Which of the following are examples of bracketing methods for finding the root of a function Solution: Bisection and False Position are examples of bracketing methods for finding the root of a function Multiple choice (Answers in bold): Choice 1) Bisection Choice 2) Newton-Raphson method Choice 3) False position Choice 4) Fixed-point iteration (Question 29)Which of the following are examples of open methods for finding the root of a function? Solution: Newton-Raphson Method, Fixed-point Iteration, and Secant Methods are examples of open methods for finding the root of a function Multiple choice (Answers in bold): Choice 1) Choice 2) Newton-Raphson Bisection method

Choice 3) Fixed-point iteration

Choice 4) Secant methods

(Question 30)Which of the following must require two initial guess to find the roots of a function? Solution: Bracketing Methods require two initial guess to find the roots of a function Multiple choice (Answers in bold): Choice 1) Bracketing methods Choice 2) Newton-Raphson method Choice 3) Fixed-point iteration Choice 4) None (Question 31)(a) Sketch the function f=inline('x^2 -4') (b) Using graphical method, what is the maximum number of roots that this function has. Solution: (a) x=-10:10; plot(x, f(x)); See the plot in the figure window. (b) Maximum number of roots = 2 Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2 (Question 32)A MATLAB code is given as follows: f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1;

Choice 3) 0

Choice 4) infinite

xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end The numerical scheme(s) used here is/are Solution: The numerical scheme used here is Newton-Raphson Multiple choice (Answers in bold): Choice 1) Bisection Choice 2) Fixed-Point (Question 33) The MATLAB code f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end finds the root for Solution: The code finds the root for f(x)=x^3 -x^2 -18 =0 and f(x)=x*x*x -x^2 -18 =0 Multiple choice (Answers in bold): Choice 1) f(x)=x^3 -x^2 -18 =0 Choice 2) f(x)=3 *x^2 - 2*x =0 Choice 3) f(x)=x*x*x -x^2 -18 =0 Choice 4) None (Question 34)Using the MATLAB code f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end If ea is the error defined in percentage, the value of the error, ea, after 5th iteration (i.e., count=5) is Solution: ea (iteration=1)=100.69 ea (iteration=2)=50.35 ea (iteration=3)=50.53 ea (iteration=4)=50.82 ea (iteration=5)=51.30 Multiple choice (Answers in bold): Choice 1) greater than 80% Choice 2) greater than 60% (Question 35)Using the MATLAB code

Choice 3) Newton-Raphson

Choice 4) Secant

Choice 3) greater than 50%

Choice 4) less than 1%

f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end What is the value of the error, ea, after 22nd iteration (i.e., count=22) Solution: ea (iteration=22)=0.0048=.48% Multiple choice (Answers in bold): Choice 1) 1% Choice 2) 0.5%

Choice 3) less than 0.5%

Choice 4) greater than 0.5%

(Question 36)Using the MATLAB code f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end The root of the function is closest to Solution: xi=3.0000 xi1=3.0001 Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 3

Choice 3) 5

Choice 4) None

(Question 37)False-position method is a bracketing with bracket xl and xu where the new root is approximated as Solution: The new root is approximated as xr = xu - f(xu)(xu - xl)/(f(xu) - f(xl)) Multiple choice (Answers in bold): Choice 1) xr = 0.5*(xl+xu) Choice 2) xr = xu - f(xu)(xu - xl)/(f(xu) - f(xl))

Choice 3) xr=(xl+xu) Choice 4) None

(Question 38)Open methods differ from bracketing methods, in that open methods Solution: Open methods require a single or two starting values that do not necessarily bracket a root and can also diverge but when they converge they usually converges at much faster rate than the bracketing methods Multiple choice (Answers in bold): Choice 1) require a single or two Choice 2) require two Choice 3) can also diverge but when they starting values that do not starting values that converge they usually converges at much necessarily bracket a root bracket a root faster rate than the bracketing methods (Question 39)Newton-Raphson method has Solution: Newton-Raphson method has quadratic convergence

Choice 4) None

Multiple choice (Answers in bold): Choice 1) linear convergence Choice 2) quadratic convergence

Choice 3) no convergence

Choice 4) None

(Question 40)Use the linspace function to create vectors identical to the colon notation x = -4:2 Solution: x = linspace(-4,2,7); Multiple choice (Answers in bold): Choice 1) x = linspace(-4,2,7); Choice 2) x = linspace(-4,7,2);

Choice 3) x = linspace(7,2,-4);

Choice 4) None

(Question 41)(a) Use the linspace function to create a vector that is identical to the colon notation t=6:4:38; (b) What is the value of t(8)? Solution: (a) t=linspace(6,38,9); (b) t(8)=34 Multiple choice (Answers in bold): Choice 1) 34 Choice 2) 32

Choice 3) 30

Choice 4) None

(Question 42)(a)Use colon notation to create vectors identical to the following created with the linspace function v = linspace (-2,1.5,8); (b)The value of v is identical to Solution: (a) v=-2:.5:1.5; (b) v=[-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5] Multiple choice (Answers in bold): Choice 1) v=[2, 1.5, 1, 0.5, 0, Choice 2) v=[-2, -1.5, -1, -0.5, 0, 0.5, -1, -1.5] 0.5, 1, 1.5]

Choice 3) v=[-2, -1.5, -1, -0.5, 0.5, 1, 1.5]

Choice 4) None

(Question 43)Which of the following MATLAB commands can be used to generate a vector z that starts from 0, ends at 50, and counts by 2. Solution: z=[0:2:50] Multiple choice (Answers in bold): Choice 1) z=[0:50] Choice 2) z=[2:0:50]

Choice 3) z=[0:2:50]

Choice 4) None

(Question 44)Which of the following MATLAB commands can be used to generate a vector w that starts at 0 counts by squares to 81 (9^2), that is 0 1 4 9 16 ... Solution: w=[0:9].^2 Multiple choice (Answers in bold): Choice 1) w=[0:9]^2 Choice 2) w=[0:9].^2

Choice 3) w=[0:9].

Choice 4) 4

(Question 45)(a) Write the MATLAB commands to generate a vector w that starts at 0 counts by 4th power to 256, that is 0 1 16 81 ... (b) Given the vector w above, what is the value of w(3)? Solution: (a) w=(0:4).^4; (c)w(3) = 16 Multiple choice (Answers in bold): Choice 1) 256 Choice 2) 81

Choice 3) 16

Choice 4) 256

(Question 46)(a) Write the MATLAB commands to generate a vector w that starts at 0 counts by squares to 81 (9^2),

that is 0 1 4 9 16 ... (b) Given the vector w above, what is w(3)? Solution: (a) w=(0:9).^2; (c)w(3) = 4 Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2 (Question 47)Given vectors x= [3,5,1,2] y=[5,6,10,8] Write the output of the following MATLAB command: x.*y Solution: ans = 15 30 10 16 Multiple choice (Answers in bold): Choice 1) 15 30 10 16 Choice 2) 10 15 30 16 (Question 48)Given vectors x= [3,5,1,2] y=[5,6,10,8] Write the output of the following MATLAB command: y' Solution: ans = 5 6 10 8 Multiple choice (Answers in bold): Choice 1) 5 6 8 10 Choice 2) 5 6 10 8 (Question 49)Given vectors x= [3,5,1,2] y=[5,6,10,8] Write the output of the following MATLAB command: y*x(2)+4 Solution: ans = 29 34 54 44 Multiple choice (Answers in bold): Choice 1) 54 44 34 29 Choice 2) 29 34 44 54

Choice 3) 3

Choice 4) 4

Choice 3) 10 15 16 30

Choice 4) None

Choice 3) 10 8 6 5

Choice 4) None

Choice 3) 29 34 54 44

Choice 4) None

(Question 50)Using a for-loop in Matlab for the given vectors V=[1 5 10 7 2]; W=[1 2 1 -3 -1]; a) Write a program that calculates dot-product of the following two vectors b) What is the value of the dot-product? Solution: V = [1 5 10 7 2]; W= [1 2 1 -3 -1]; n=length(V); dot_product=0; for i=1:n; dot_product = dot_product + V(i)*W(i); end fprintf('dot product = %f \n',dot_product)

dot product = -2.000000 Multiple choice (Answers in bold): Choice 1) -2 Choice 2) -1 (Question 51)If b=5; b=b+1; a =2*b + 1; What is the value of c if c=a+b? Solution: b=5 b=b+1 b=5+1=6 a=2*b + 1 a=2*6 + 1=13 c=a+b c=13+6=19 Multiple choice (Answers in bold): Choice 1) 6 Choice 2) 13 (Question 52)If a=3; a=a^2; b=a+1; What is the value of c if c=a*b? Solution: a=3 a=a^2 a=3^2=9 b=a+1 b=9+1=10 c=a*b c=9*10=90 Multiple choice (Answers in bold): Choice 1) 90 Choice 2) 12 (Question 53)If c=2; c=4*c; c=c^2+1; b=2*c; What is the value of a if a=b+c Solution: c=2 c=4*c c=4*2=8 c=c^2+1 c=8^2+1 c=65 b=2*c b=2*65=130 a=b+c a=130+65

Choice 3) 0

Choice 4) 1

Choice 3) 19

Choice 4) 16

Choice 3) 19

Choice 4) 42

a=195 Multiple choice (Answers in bold): Choice 1) 24 Choice 2) 6 (Question 54)If a=2; a=a^2; What is the value of a+3? Solution: a=2 a=a^2 a=2^2 a=4 a+3=4+3=7 Multiple choice (Answers in bold): Choice 1) 5 Choice 2) 7 (Question 55)If a=1; b=a+5 What is the value of d if d=a*(b^2)? Solution: a=1 b=a+5 b=1+5=6 d=a*(b^2) d=1*(6^2)=36 Multiple choice (Answers in bold): Choice 1) 12 Choice 2) 36 (Question 56)If b=10; b=b^2; What is the value of b=b+2? Solution: b=10 b=b^2 b=10^2=100 b=b+2 b=100+2=102 Multiple choice (Answers in bold): Choice 1) 12 Choice 2) 20 (Question 57)If c=1; c=c^3; What is the value of c=c+9 Solution: c=1 c=c^3 c=1^3=1 c=c+9 c=1+9=10 Multiple choice (Answers in bold): Choice 1) 12 Choice 2) 21

Choice 3) 195

Choice 4) None

Choice 3) 8

Choice 4) 4

Choice 3) 25

Choice 4) None

Choice 3) 110

Choice 4) 102

Choice 3) 10

Choice 4) None

(Question 58)If a=4; a=a+1; b=a^2; What is the value of c if c=a*b? Solution: a=4 a=a+1 a=4+1=5 b=a^2 b=5^2=25 c=a*b c=5*25=125 Multiple choice (Answers in bold): Choice 1) 125 Choice 2) 64 (Question 59)If f=10; f=f+1; What is the value of f^2? Solution: f=10 f=f+1 f=10+1=11 f^2=11^2=121 Multiple choice (Answers in bold): Choice 1) 100 Choice 2) 101 (Question 60)If g=1; h=g+10; h=h^2; What is the value of f if f=g*h? Solution: g=1 h=g+10 h=1+10=11 h=h^2 h=11^2=121 f=g*h f=1*121=121 Multiple choice (Answers in bold): Choice 1) 11 Choice 2) 121

Choice 3) 32

Choice 4) None

Choice 3) 121

Choice 4) 22

Choice 3) 1

Choice 4) 122

(Question 61)Exactly what will be displayed after the following MATLAB commands are types? a) >> x=5; >> x^3; >> y=8-x; b) >> q = 4:2:12; >> r = [7 8 4 ; 3 6 -5] ; >> sum(q) * r(2, 3) c) What is the value of sum(q) * y Solution: a) 3; b) -200; c) 120 Multiple choice (Answers in bold): Choice 1) -200 Choice 2) 120

Choice 3) 40

Choice 4) None

(Question 62)a) In the absence of air resistance, the Cartesian coordinates of a projectile launched with an initial velocity (v0) and angle (theta) can be computed with

x = v0 * cos(theta) * t; y = v0*sin(theta) * t - g * t * t /2; where g =9.81 m/s2. Develop a MATLAB script to generate a plot of the projectile's trajectory given that v0 =5 m/s and theta0=45 degree. b) The maximum height that the projectile will reach is closest to Solution: t=0:.1:2; v0=5; theta=45; g=9.81; t_radian=theta*pi/180; x=v0*cos(t_radian)*t; y=v0*sin(t_radian)*t - g*t.^2/2; plot(x,y); b) t=v0*sin(t_radian)/g; y=v0*sin(t_radian)*t - g*t.^2/2; Multiple choice (Answers in bold): Choice 1) 0.3604 Choice 2) 0.6371

Choice 3) 1

Choice 4) 2

(Question 63)a) In the absence of air resistance, the Cartesian coordinates of a projectile launched with an initial velocity (v0) and angle (theta) can be computed with x = v0 * cos(theta) * t; y = v0*sin(theta) * t - g * t * t /2; where g =9.81 m/s2. Develop a MATLAB script to generate a plot of the projectile's trajectory given that v0 =5 m/s and theta0=45 degree. b) How long will it take for the projectile to reach the maximum height Solution: t=0:.1:2; v0=5; theta=45; g=9.81; t_radian=theta*pi/180; x=v0*cos(t_radian)*t; y=v0*sin(t_radian)*t - g*t.^2/2; plot(x,y); b) t=v0*sin(t_radian)/g; Multiple choice (Answers in bold): Choice 1) 0.3604 Choice 2) 0.6371

Choice 3) 1

Choice 4) 2

(Question 64)(a) Write a MATLAB code using for-loop to compute C=A*A where A=[1 3; 4 5]; (b) The value of C(2,2) is Solution: (a) A=[1 3; 4 5]; for i=1:2; for j=1:2; C(i,j)=0; for k=1:2; C(i,j) = C(i,j) + A(i,k)*A(k,j); end end end (b) 37 Multiple choice (Answers in bold): Choice 1) 13 Choice 2) 18

Choice 3) 24

Choice 4) 37

(Question 65)The "divide and average" method to find the square root of 2 is given by x = (x + 2/x)/2; (a) Write a MATLAB Script using for-loop to find the square root of 2 for 4 iterations with starting guess for x=1. What is the value (or closest value) of x after the 2nd iterations Solution: xold=1; for i=1:4; xnew = (xold + 2/xold)/2; disp([xold xnew i]); xold=xnew; end Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 1.4167

Choice 3) 1.4142

Choice 4) 1.5

(Question 66)The "divide and average" method to find the square root of 2 is given by x = (x + 2/x)/2; (a) Write a MATLAB Script using while-loop to find the square root of 2 for 4 iterations with starting guess for x=1. What is the value (or closest value) of x after the 3rd iterations Solution: xold=1; i=1;

while (i<=4) xnew = (xold + 2/xold)/2; disp([xold xnew i]); xold=xnew; i=i+1; end Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 1.4167

Choice 3) 1.4142

Choice 4) 1.5

(Question 67)The "divide and average" method to find the square root of 16 is given by x = (x + 16/x)/2; (a) Write a MATLAB Script using while-loop and if-break condition to find the square root of 16 for 4 iterations with starting guess for x=1. What is the value (or closest value) of x after the 3rd iterations Solution: xold=1; i=1; while (1==1) xnew = (xold + 16/xold)/2; disp([xold xnew i]); if(i==4) break; end; xold=xnew; i=i+1; end Multiple choice (Answers in bold): Choice 1) 8.5000 Choice 2) 4

Choice 3) 4.1367

Choice 4) 4.0023

(Question 68)The "divide and average" method to find the square root of 16 is given by x = (x + 16/x)/2; A MATLAB Script using while-loop and if-break condition to find the square root of 16 for 4 iterations with starting guess for x=1 is given by
xold=1; i=1; while (1==1) xnew = (xold +,16/xold)/2; disp([xold xnew i]); if(i==4) break; end; xold=xnew; i=i+1; end

(a) This code has a bug. Fix the bug and write the correct code. (b) What is the value (or closest value) of x after the 4th iterations Solution: xold=1; i=1; while (1==1) xnew = (xold + 16/xold)/2; disp([xold xnew i]); if(i==4) break; end; xold=xnew; i=i+1; end Multiple choice (Answers in bold): Choice 1) 8.5000 Choice 2) 4

Choice 3) 4.1367

Choice 4) 4.0023

(Question 69)(a) A MATLAB code to compute magnitude of a vector v is given by:


mag_v=0; v=[1 3 5]; for i=1:length(v); mag_v=mag_v + v(i)*2; end; mag_v=sqrt(mag_v);

This code however has a bug. Fix the bug and write the correct code. <b> If v=[1 3 5]; what is the correct value of mag_v? Solution:
mag_v=0; v=[1 3 5]; for i=1:length(v); mag_v=mag_v + v(i)^2; end; mag_v=sqrt(mag_v);

Multiple choice (Answers in bold):

Choice 1) 3

Choice 2) 5

Choice 3) 5.9161

Choice 4) 4.2426

(Question 70)(a) A MATLAB code to compute magnitude of a vector v is given by:


mag_v=0; v=[3 4]; for i=1:length(v); mag_v=mag_v + v(i^2); end; mag_v=sqrt(mag_v);

This code however has a bug. Fix the bug and write the correct code. <b> If v=[3 4]; what is the correct value of mag_v? Solution:
mag_v=0; v=[1 3 5]; for i=1:length(v); mag_v=mag_v + v(i)^2; end; mag_v=sqrt(mag_v);

Multiple choice (Answers in bold): Choice 1) 3 Choice 2) 5

Choice 3) 5.9161

Choice 4) 4

(Question 71)(a) Sketch the function f=inline('x^2 -2') (b) Using graphical method, approximately find the value of x (root of the function) such that f(x)=0. (c) Write a MATLAB script for 4 iterations of Bi-section method with xL=0; and xU=2.0; (d) What is the closest value of xR after the 4th iteration? Solution: (a)
xL = 0; xU = 2; fU = xU^2 - 2; fL=xL^2 - 2; n=4; for i=1:n fR = xR^2 - 2; fL = xL^2 -2; fU = xU^2 - 2; if(fR*fL > 0 ) xL = xR; else xU = xR; end xR = xU - (fU) * (xL-xU)/(fL-fU); disp([i xL xU xR]) end

Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 1.5000 (Question 72)A MATLAB code is given as follows:

Choice 3) 1.3583

Choice 4) 1.414

f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end

The numerical scheme(s) used here is/are Solution: The numerical scheme used here is Newton-Raphson with xi=0.5. Note that x(i+1) = x(i) - f(x(i)) / f'(x(i)); Multiple choice (Answers in bold):

Choice 1) Bisection with xL=0; xU=1; (Question 73) The MATLAB code

Choice 2) Fixed-Point with Choice 3) Newton-Raphson xi=0.5 with xi=0.5

Choice 4) Secant with xi=0.5

f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end

finds the root for Solution: The code finds the root for f(x)=x^3 -x^2 -18 =0 and f(x)=x*x*x -x^2 -18 =0 using Newton-Raphson method Multiple choice (Answers in bold): Choice 1) f(x)=x^3 -x^2 Choice 2) f(x)=3 *x^2 - 2*x -18 =0 using secant =0 using Newton Raphson method method (Question 74)Using the MATLAB code
f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end

Choice 3) f(x)=x*x*x -x^2 -18 Choice 4) f(x)=x^3 -x^2 -18 =0 using Newton-Raphson =0 using false position Method method

If ea is the error defined in percentage, the value of the error, ea, after 5th iteration (i.e., count=5) is closest to Solution: ea (iteration=1)=100.69 ea (iteration=2)=50.35 ea (iteration=3)=50.53 ea (iteration=4)=50.82 ea (iteration=5)=51.30 Multiple choice (Answers in bold): Choice 1) greater than 80% (Question 75)Using the MATLAB code
f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - df(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1);

Choice 2) 50.35

Choice 3) 51.30

Choice 4) 20%

end

disp([count xi1,xi, ea]); xi=xi1;

(a) Fix the bug and write the correct code. (b)Using the correct code, what is the value of the error, ea, after 22nd iteration (i.e., count=22) closet to Solution:
f=inline('x^3 - x^2 -18'); df=inline('3*x^2 - 2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end

ea (iteration=22)=0.0048=.48% Multiple choice (Answers in bold): Choice 1) 10% Choice 2) 1.2%

Choice 3) 0.48%

Choice 4) 0.5%

(Question 76)(a) Find the bug and fix it in the the following Newton-Raphson code to find the square root of 3 and write the correct code.
f=inline('x^2 - 7'); df=inline('2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi1 - f(xi),/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end

Using The root (xi1) of the function after 5th iteration (count=5) is closest to Solution:
f=inline('x^2 - 7'); df=inline('2*x'); ea=100; count=0; xi=0.5; while (ea>.01); count = count + 1; xi1 = xi - f(xi)/df(xi); ea = 100*abs((xi1-xi)/xi1); disp([count xi1,xi, ea]); xi=xi1; end

Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2.6458

Choice 3) 7.2500

Choice 4) 93.1034

(Question 77)False-position method is a bracketing with bracket xl and xu where the new root is approximated as xr = xu - f(xu)(xu - xl)/(f(xu) - f(xl)) (a) Write a Matlab script to compute the root for f(x) = x^3 - 27; after the 7th iterations. Use xL=0; xU=10; (b) What is the value of the root closest to after the 3rd iteration?

Solution:
xL = 0; xU = 10; fU = xU^3 - 27; fL=xL^3 - 27; xR = xU - (fU) * (xL-xU)/(fL-fU); n=7; for i=1:n fR = xR^3 - 27; fL = xL^3 -27; fU = xU^3 - 27; if(fR*fL > 0 ) xL = xR; else xU = xR; end xR = xU - (fU) * (xL-xU)/(fL-fU); disp([i xL xU xR]) end

(b) 1.0355 Multiple choice (Answers in bold): Choice 1) 0.5327 Choice 2) 1.0355

Choice 3) 2

Choice 4) 3

(Question 78)False-position method is a bracketing with bracket xl and xu where the new root is approximated as xr = xu - f(xu)(xu - xl)/(f(xu) - f(xl)) (a) Matlab script with a bug to compute the root for f(x) = x^3 - 27; after the 7th iterations using xL=0; xU=10; is given by
xL = 0; xU = 10; fU = xU^3 - 27; fL=xL^3 - 27; xR = xU - (fU) * (xL-xU)/(fL-fU); n=7; for i=1:n fR = xR^3 - 27; fL = xL^3 -27; fU = xU^3 - 27; if(fR*fL < 0 ) xL = xR; else xU = xR; end xR = xU - (fU) * (xL-xU)/(fL-fU); disp([i xL xU xR]) end

Fix the bug and write the correct code. (b) What is the value of the root closest to after the 3rd iteration? Solution:
xL = 0; xU = 10; fU = xU^3 - 27; fL=xL^3 - 27; xR = xU - (fU) * (xL-xU)/(fL-fU); n=7; for i=1:n fR = xR^3 - 27; fL = xL^3 -27; fU = xU^3 - 27; if(fR*fL > 0 ) xL = xR; else xU = xR; end xR = xU - (fU) * (xL-xU)/(fL-fU); disp([i xL xU xR]) end

(b) 0.5327 Multiple choice (Answers in bold): Choice 1) 0.5 Choice 2) 1 (Question 79)Secant method is given by
df = (f(i+1) - f(i))/(x(i+1)-x(i)); x(i+2) = x(i+1) - f(i+1)/df;

Choice 3) 2

Choice 4) 3

Write a MATLAB Script using for for-loop to compute the root of f(x) = x^4 - 16 after 6-iterations; Use x(1) = 0; x(2) =1; What is the value of the root closest to after 2nd iteration (i.e., i=2)? Solution:

n=3; for i=1:n df=(f2 - f1)/(x2-x1); x3 = x2 - f2/df; f3=x3^4-16; disp([i x1 x2 x3]) x1=x2; x2=x3; f1=f2; f2=f3; end

x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16;

Multiple choice (Answers in bold): Choice 1) 0 Choice 2) 2 (Question 80)Secant method is given by
df = (f(i+1) - f(i))/(x(i+1)-x(i)); x(i+2) = x(i+1) - f(i+1)/df;

Choice 3) 5

Choice 4) 1

A MATLAB Script (with bug) using for for-loop to compute the root of f(x) = x^4 - 16 is given by
x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16; n=3; for i=1:n df=(f2 - f1)/(x2-x1); x3 = x2 - f2/df; f3=x3^4-16; disp([i x1 x2 x3]) end

Fix the bug and write the correct code. What is the value of the root closest to after 15th iteration (i.e., n=15)? Solution:
x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16; n=15; for i=1:n df=(f2 - f1)/(x2-x1); x3 = x2 - f2/df; f3=x3^4-16; disp([i x1 x2 x3]) x1=x2; x2=x3; f1=f2; f2=f3; end

Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2 (Question 81)Secant method is given by
df = (f(i+1) - f(i))/(x(i+1)-x(i)); x(i+2) = x(i+1) - f(i+1)/df;

Choice 3) 3

Choice 4) 4

A MATLAB Script (with bug) using for for-loop to compute the root of f(x) = x^4 - 16 is given by
x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16;

n=3; for i=1:n df=(f2 - f1)/(x2*x1); x3 = x2 - f2/df; f3=x3^,4-16;

end

disp([i x1 x2 x3]) x1=x2; x2=x3; f1=f2; f2=f3;

Fix the bug and write the correct code. What is the value of the root closest to after 7th iteration (i.e., n=7)? Solution:
x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16;

n=7; for i=1:n df=(f2 - f1)/(x2-x1); x3 = x2 - f2/df; f3=x3^4-16; disp([i x1 x2 x3]) x1=x2; x2=x3; f1=f2; f2=f3; end

Multiple choice (Answers in bold): Choice 1) 1 Choice 2) 2 (Question 82)Secant method is given by
df = (f(i+1) - f(i))/(x(i+1)-x(i)); x(i+2) = x(i+1) - f(i+1)/df;

Choice 3) 3

Choice 4) 4

A MATLAB Script (with bug) using for for-loop to compute the root of f(x) = x^4 - 16 is given by
x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16; n=3; for i=1:n df=(f2 - f1)*(x2-x1); x3 = x2 + x2/df; f3=x3^4-16; disp([i x1 x2 x3]) x1=x2; x2=x3; f1=f2; f2=f3; end

Fix the bug and write the correct code. What is the value of the root closest to after 8th iteration (i.e., n=8)? Solution:
x1 = 0; f1=x1^4-16; x2 = 1; f2=x2^4-16;

n=8; for i=1:n df=(f2 - f1)/(x2-x1); x3 = x2 - f2/df; f3=x3^4-16; disp([i x1 x2 x3]) x1=x2; x2=x3; f1=f2; f2=f3; end

Multiple choice (Answers in bold): Choice 1) 1.5 Choice 2) 2.5 Printing All the question & existing

Choice 3) 3

Choice 4) 4.5

Anda mungkin juga menyukai