Quiz 3.1This quiz provides a quick check to see if you have understood the concepts introduced in Section 3.3. If you have trouble with the quiz, reread the sections, ask your instructor, or discuss the material with a fellow a, b, c, and d are as defined, and evaluate the following expressions.Assume that a, b, c, and d are as defined, and evaluate the following expressions.a= 20; b= -2; c= 0; d= 1;1. a > b>> ans = 12. b > d>> ans = 03. a > b & c > d>> ans = 04. a == b>> ans = 05. a & b > c>> ans = 06. ~~ b>> ans = 1a= 2; b= [1 -2; -0 10]; c= [0 1; 2 0]; d= [-2 1 2; 0 1 0];7. ~(a > b)>> ans =0 00 18. a > c & b >c>> ans =1 00 19. c > ??? Error using ==> a*c>> ans = 011. d | b > a>> ans = 112. (d | b) > a>> ans = 0a= 20; b= -2; c= 0; d= 'Test';13. isinf(a/b)>> ans = 014. isinf(a/c)>> ans = 115. a > b & ischar(d)>> ans = 116. isempty(c)>> ans = 0Quiz 3.2Write MATLAB statements that perform the functions described below.1. If x is greater than or equal to zero, then assign the square root of xto variable sqrt-x and print out the result. Otherwise, print out an error message about the argument of the square root function, and set sqrt-x to zero.x= input('x = ');if x >= 0sqrt_x = sqrt(x)elsesqrt_x = 0disp('error : x
quiz 3.31. Write the MATLAB statements required to plot sin x versus cos 2x from 0 to 2n in steps of d10. The points should be connected by a 2-pixel-wide red line, and each point should marked with a h-pixelwide blue circular marker.>> x= 0:pi/10:2*pi;x1= sin(x);y1= cos(2*x);plot(x1,y1, '-ro','LineWidth',2,'MarkerSize',6,'MarkerEdgeColor','b','MarkerFaceColor','b')2. Use the Figure editing tools to change the markers on the previous plot into black squares. Add an arrow and annotation pointing to the location x = n on the plot.Write the MATLAB text string that will produce the following expressions:>>3. f (x) = sin ヨ cos 2ヰ>> 'itfrm(itxrm) = sintheta cos2phi'4. plot of ヒx^2 versus x>> 'bfplot of sigma itxrmbf^{2} versus itx'Write the expression produced by the following text strings:5. ' tauit_{m} '>> ンm6. 'bfitx_{l)^{2) + x_{2}^{2} rm(units: bfm^{2)rm) '>> x1^2 + x2^2 (unit: m^2)7. How do you display the backslash () character in a text string?>> ' \ '3.1(a) 5.5 >= 5>> 1(b) 20 > 20>> 0(c) xor( 17 - pi < 15, pi < 3)>> 1(d) true > false>> 1(e) --(35/17) == (35/17)>> 1(f) (7 > 0(g) 17.5 && (3.3 > 2.)>> 13.5In Example 3.3, we wrote a program to evaluate the function f(x, y) for any two user-specified values x and y, where the function f(x, y) was defined as follows.The problem was solved by using a single if construct with four code blocks to calculate f(x, y) for all possible combinations of x and y. Rewrite program funxy to use nested if constructs, where the outer construct evaluates the value of x and the inner constructs evaluate the value of y.>> x= input('enter the x coefficient: ');y= input('enter the y coefficient: ');if x>=0 && y>=0fun = x + y;elseif x>=0 && y>n=1;R=8.314;T=250:3:400;V=10;P=(n*R*T) ./V;plot(T,P);title('bfthe pressure of the gas as a function of temperature')xlabel('temperature (K)')ylabel('pressure')3.17Plotting Orbits When a satellite orbits the Earth, the satellite's orbit will form an ellipse with the Earth located at one of the focal points of the ellipse. The satellite's orbit can be expressed in polar coordinates as where r and ヨ are the distance and angle of the satellite from the center of the Earth, ヱ is a parameter specifying the size of the size of the orbit, and ュ is a parameter representing the eccentricity of the orbit. A circular orbit has an eccentricity ュ of 0. An elliptical orbit has an eccentricity of 0 ュ 1. If ュ > 1, the satellite follows a hyperbolic path and escapes from the Earth's gravitational field.Consider a satellite with a size parameterp = 1000 krn. Plot the orbit of this satellite if (a) ュ = 0; (b) ュ = 0.25; (c) ュ = 0.5. How close does each orbit come to the Earth? How far away does each orbit get from the Earth? Compare the three plots you created. Can you determine what the parameter ヱ means from looking at the plots?>>theta= 0:0.1:2*pi;p=1000;e=0;r1=p./(1-e*cos(theta));e=0.25;r2=p./(1-e*cos(theta));e=0.5;r3=p./(1-e*cos(theta));polar(theta, r3, 'r');hold on;polar(theta, r2, 'g');hold on;polar(theta, r1 ,'b');
Quiz 2.11. what is the difference between an array, a matrix, and a vector?>> array is a collection of data values organized into row and columns.matrix is usually used to describe an array with two or more dimensions.vector is usually used to describe an array with only one dimension.2. answer the following questions for the array shown below.c=[1.1 -3.2 3.4 0.6; 0.6 1.1 -0.6 3.1; 1.3 0.6 5.5 0.0](a) what is the size of c? >> 3*4(b) what is the value of c(2, 3)? >> -0.6(c) list the subscripts of all elements containing the value 0.6.3. determine the size of the following arrays. c rs by entering the arrays into matlab and using the whos command or the workspace browser. note that the later arrays may depend on the definitions of arrays defined earlier in this exercise.(a) u= [ 10 20*i 10+20 ];(b) v= [ -1; 20; 3];(c) w= [ 1 0 -9; 2 -2 0; 1 2 3 ];(d) x= [ u' v ];(e) y(3,3) = -7;(f) z= [ zeros(4,1) ones(4,1) zeros(1,4)' ];(g) v(4)= x(2,1);>> whosName Size Bytes Classu 1x3 48 double array (complex)v 4x1 64 double array (complex)w 3x3 72 double arrayx 3x2 96 double array (complex)y 3x3 72 double arrayz 4x3 96 double array4. what is the value of w(2,1) above?w =1 0 -92 -2 01 2 3>> 25. what is the value of x(2,1) above?x =10 -10-20i 2030 3>> 0-20i6. what is the value of y(2,1) above?y =0 0 00 0 00 0 -7>> 07.what is the value of v(3) after statement (g) is executed?v =-1.000020.00003.00000 -20.0000i>> 3Quiz 2.21. assume that array c is defined as shown, and determine the contents of the following subarrays:c= [ 1.1 -3.5 3.4 0.6; 0.6 1.1 -0.6 3.1; 1.3 0.6 5.5 0.0 ](a) c(2,:)>> 0.6000 1.1000 -0.6000 3.1000(b) c(:,end)>> 0.60003.10000(c) c(1:2,2:end)>> -3.5000 3.4000 0.60001.1000 -0.6000 3.1000(d) c(6)>> 0.6000(e) c(4:end)>> -3.5000 1.1000 0.6000 3.4000 -0.6000 5.5000 0.6000 3.1000 0(f) c(1:2,2:4)>> -3.5000 3.4000 0.60001.1000 -0.6000 3.1000(g) c([1 3] , 2)>> -3.20.6(h) c([2 2],[3 3])-0.6000 -0.6000-0.6000 -0.60002. determine the contents of array a after the following statements are executed.(a) a = [ 1 2 3; 4 5 6; 7 8 9 ];a([ 3 1 ], :) = a([ 1 3 ], :);>> a =7 8 94 5 61 2 3(b) a = [ 1 2 3; 4 5 6; 7 8 9 ];a([ 1 3 ], :) = a([ 2 2 ], :);>> a =4 5 64 5 64 5 6(c) a = [ 1 2 3; 4 5 6; 7 8 9 ];a = a([ 2 2 ], :);>> a =4 5 64 5 63. determine the contents of array a after the following statements are executed.(a) a = eye(3,3); b = [ 1 2 3 ];a(2,:) = b;>> a =1 0 01 2 30 0 1(b) a = eye(3,3); b = [ 4 5 6 ];a(:,3) = b';>> a =1 0 40 1 50 0 6(c) a = eye(3,3); b = [ 7 8 9 ];a(3,:) = b([ 3 1 2 ]);>> a =1 0 00 1 09 7 8(d) a = eye(3,3); b = [ 7 8 9 ];a(3,:) = b([ 3 1 2 ]);>> a =1 0 00 1 09 7 8Quiz 2.31. how would you tell MATLAB to display all real values in exponential format with 15 significant digits?>> format long e : 15 digits plus exponent ex) 1.2345678901234567e+0012. what do the following sets of statements do? what is the output from them?(a)radius = input('enter circle radius:n');area = pi * radius^2;str = ['the area is ' num2str(area)];disp(str);>> enter circle radius: 5 (5는 임의숫자)the area is 78.5398(b) value = int2str(pi)>> value =3disp(['the value is ' value '!']);>> the value is 3!3. what do the following sets of statements do? what is the output from them?value = 123.4567e2>>value = 1.2346e+004fprintf('value = %en', value);>> value = 1.234567e+004fprintf('value = %fn', value);>> value = 12345.670000fprintf('value = %gn', value);>> value = 12345.7fprintf('value = %12.4f n', value);>>value = 12345.6700Quiz 2.41. assume that a, b, c, and d are defined as follows, and calculate the results of the following operations if they are legal. if an operation is illegal, explain why it is illegal.a= [ 2 1; -1 2 ] b= [ 0 -1; 3 1 ] c= [ 1; 2 ] d= -3(a)result = a .* c>> illegal, why?a .* c에서 .이 있으므로 같은 위치에 있는 것끼리 계산을 해야하는데, a의 size는 2*2이고 c의 size는 2*1 이므로써 size가 서로 달라 이 함수를 적용할 수가 없다.(b)result = a * [c c];>>ans =4 43 3(c)result = a .* [c c];>>ans =2 1-2 4(d)result = a + b * c;>> illegal, why?b * c = [ -2; 5] 그러나 a의 size는 2*2 이고 b*c의 size는 2*1 이므로써 size가 서로 달라 이 함수를 적용할 수가 없다.(e)result = a + b .* c;>> illegal, why?b .* c에서 .이 있으므로 같은 위치에 있는 것끼리 계산을 해야하는데, b의 size는 2*2 이고 c의 size는 2*1 이므로써 size가 서로 달라 이 함수를 적용할 수가 없다.2. solve for x in the equation Ax = B,where A = [ 1 2 1; 2 3 2; -1 0 1 ] and B = [ 1; 1; 0 ]>> x =-0.50001.0000-0.5000
2.1array1= [1.1 0.0 2.1 -3.5 6.0; 0.0 1.1 -6.6 2.8 3.4;2.1 0.1 0.3 -0.4 1.3; -1.4 5.1 0.0 1.1 0.0]a. what is the size of array1?>> 4*5b. what is the value of array1(4,1)?>> -1.4000c. what is the size and value of array1 (:, 1:2)?>> 4*2>> 1.1000 00 1.10002.1000 0.1000-1.4000 5.1000d. what is the size and value of array1 ([1 3], end)?>> 2*1>> 6.00001.30002.3 determine the size and contents of the following arrays. note that the later arrays may depend on the definitions of arrays defined earlier in this exercise.a. a= 1: 2: 5;>> a =1 3 5b. b= [a' a' a'];>> b =1 1 13 3 35 5 5c. c= b(1:2:3, 1:2:3);>> c =1 15 5d. d= a + b(2,:);>> d =4 6 8e. w= [zeros(1,3) ones(3,1)' 3:5'];>> w =0 0 0 1 1 1 3 4 5f. b([1 3], 2) = b([3 1], 2);>> b =1 1 13 3 35 5 52.4array1= [1.1 0.0 2.1 -3.5 6.0; 0.0 1.1 -6.6 2.8 3.4;2.1 0.1 0.3 -0.4 1.3; -1.4 5.1 0.0 1.1 0.0]a. array1(3, :)>> ans =2.1000 0.1000 0.3000 -0.4000 1.3000b. array1(:, 3)>> ans =2.1000-6.60000.30000c. array1(1:2:3, [3 3 4])>> ans =2.1000 2.1000 -3.50s =1.1000 0 2.1000 -3.5000 6.00001.1000 0 2.1000 -3.5000 6.00002.6a= [2 -2; -1 2] b= [1 -1; 0 2] c= [1; -2] d=eye(2)a. result = a +b;>> legal>> result =3 -3-1 4b. result = a * d;>> legal>> result =2 -2-1 2c. result = a .* d;>> legal>> result =2 00 2d. result = a * c;>> legal>> result =6-5e. result = a .*c;>> illegal, why?a .* c에서 .이 있으므로 같은 위치에 있는 것끼리 계산을 해야하는데, a의 size는 2*2이고 c의 size는 2*1 이므로써 size가 서로 달라 이 함수를 적용할 수가 없다.f. result = a b;>> legal>> result =1.0000 1.00000.5000 1.5000g. result = a . b;>> legal>> result =0.5000 0.50000 1.0000h. result = a .^ b;>> legal>> result =2.0000 -0.50001.0000 4.00002.9 solve the following system of simultaneous equations for x.-2.0x1 + 5.0x2 + 1.0x3 + 3.0x4 + 4.0x5 - 1.0x6 = 0.02.0x1 - 1.0x2 - 5.0x3 - 2.0x4 + 6.0x5 + 4.0x6 = 1.0-1.0x1 + 6.0x2 - 4.0x3 - 5.0x4 + 3.0x5 - 1.0x6 = -6.04.0x1 + 3.0x2 - 6.0x3 - 5.0x4 - 2.0x5 - 2.0x6 = 10.0-3.0x1 + 6.0x2 + 4.0x3 + 2.0x4 - 6.0x5 + 4.0x6 = -6.02.0x1 + 4.0x2 + 4.0x3 + 4.0x4 + 5.0x5 - 4.0x6 = -2.0>>a=[-2 5 1 -5 -2 -2; -3 6 4 2 -6 4; 2 4 4 4 5 -4];b=[0; 1; -6; 10; -6; -2];ax=bx= abx =0.6626-0.1326-3.01372.8355-1.0852-0.83602.10 position and velocity of a ball.if a stationary ball is released at a height h0 above the surface of the earth with a vertical velocity v0, the position and velocity of the ball as a function of time will be given by the equationsh(t)= 1/2*g*t^2 + v0*t + h0 ---(2.10)v(t)= g*t + v0 ---(2.11)where g is the acceleration due to gravity(-9.81 m/s^2), h is the height above the surface of the earth(assuming no air friction), and v is the vertical component of velocity. write a matlab program that prompts a user for the initial height of the ball in meters and velocity of the ball in meters per second, and plots the height and velocity as a function of time. be sure to include proper labels in your plots.>>v0= input('lnitial velocity : ');h0= input('lnitial height : ');t0= input('time : ');g= -9.81;t= 0:0.1:t0;h= 0.5*g*t.^2 + v0*t + h0;v= g*t + v0;plot(t, h);title('positiobove the surfave of the earth');ylabel('the vertical component of velocity');legend('ddddd', 'Location', 'Best');grid on;2.11the distance between two points (x1, y1) and (x2, y2) on a cartesian coordinate plane is given by the equationd= [(x1 - x2)^2 + (y1 - y2)^2]^(-1/2) ---(2.12)write a program to calculate the distance between any two points (x1, y1) and (x2, y2) specified by the user. use good programmaing practices in your program. use the program to calculate the distance between the points (2,3) and (8,-5).>>x1=2;x2=8;y1=3;y2=-5;d= [(x1 - x2)^2 + (y1 - y2)^2]^(-1/2)d =0.10002.13 hyperbolic cosine.the hyperbolic cosine function is defined by the equationcosh(x)= (e^x + e^-x)/2 ---(2.14)write a program to calculate the hyperbolic cosine of a user-supplied value x. use the program to calculate the hyperbolic cosine of 3.0. compare the answer that your program produces to the answer produced by the function cosh(x). what is the smallest value that this function can have? at what val= cosh(x);y2= [exp(x) + exp(-x)]/2;plot(x,y1,'k--', x,y2,'b-');>>x=3y1 =10.0677y2 =10.06772.14 energy stored in a springthe force required to compress a linear spring is given by the equationF = k*x ---(2.15)where F is the force in newtons and k is the spring constant in newtons per meter. the potential energy stored in the compressed spring is given by the equationE = (1/2)*k*x^2 ---(2.16)where E is the energy in joules. the following information is available for four springs.spring 1spring 2spring 3spring 4Force(N)20242220spring constant k(N/m)500600700800determine the compression of each spring, and the potential energy stored in each spring. which spring has the most energy stored in it?>>%spring1F=20;k=500;x= F/k>>x =0.0400E = (1/2)*k*x^2;>>E =0.4000%spring2F=24;k=600;x= F/k>>x =0.0400E = (1/2)*k*x^2;>>E =0.4800%spring3F=22;k=700;x= F/k>>x =0.0314E = (1/2)*k*x^2;>>E =0.3457%spring4F=20;k=800;x= F/k>>x =0.0250E = (1/2)*k*x^2;>>E =0.2500spring1 E= 0.4000spring2 E= 0.4800spring3 E= 0 있다.
Quiz 1.1what is the purpose of the MATLAB Command Window? The Edit/Debug Window? The Figure Window?(a)Command Window? >> a user can enter interactive commands at the command prompt in the command window, and they will be executed on the spot.(b)Edit/Debug Window?>> it is used to create new M-file, or to modify existing ones.(c)The Figure Window? >> it is used to display MATLAB graphics. a figure can be a two-or three-dimensional plot of data, an image, or a graphical user interface. Exercises 1.1 The following MALTAB statements plot the function y(x)=2e^-0.2x for the range 0<=x<=10.x = 0: 0.1: 10;y = 2* exp (-0.2* x);plot(x,y);Use the MATLAB edit window to create a new empty M-file, type these statements into the file, and save the file with the name test1.m. Then, execute the program by typing the name test1 in the command window. What result do you get? >> pop up the test1 figure window, so I can see the gragh and data `x`, `y` in workspace.