650:231 M.E. Computational Analysis and Design Homework #2: Intro to MATLAB 1. [4 points] Write the script or function m-file to compute , where indicates the summation from n=1 to M and run the case M=10. (a) Using for/end, but not array operators or sum . This is the standard. (b) Using array operators and sum , but not for/end . [Hint: Create an array of ratios , using the array operator.] Submit the codes and the numerical results. 2 . [3 points] Write a function m-file that calculates the roots of . Its synopsis is QuadRoots(a,b,c), where a, b and c are allowed to be vectors. First, use the example below to get the results (and show them), then give your own input of coefficient vectors a, b and c and perform the calculation and show the results. Finally, check your results with the roots command, which is a built-in MATLAB command to do the job. For example >> a=[1,2,3]; >> b=[2,3,4]; >> c=[3,4,5]; will produce the coefficients of three quadratic polynomials: When you issue the command
This is the end of the preview. Sign up
access the rest of the document.