Question

Homework Assignment #3 - Part 2 This assignment is worth 100 points and consists of two parts. This is Part 2, which covers user-defined functions. Both Part 1 and 2 are

due Wednesday, March 13th on Canvas. Code must be written in MATLAB, be well documented, and be composed as follows: Part 1 should be solved with one M file using sections. Part 2 should be solved with multiple function files and a single script using sections that calls your functions. 1. Recall the built-in Matlab function poly2sym. Here, we will implement our own version of this function. (For full points, do not use the built-in poly2sym function.) Your function should take two input variables: The first input variable should be an array of numerical values representing the coefficients of the polynomial to be created. The second input variable should be a symbolic variable representing the variable of your univariate polynomial. Create the symbolic polynomial based on the inputs, then return it. Below are some example inputs and outputs that are expected: >> syms x y z >> myPoly2Sym([213],x) ans 2*x^2+x+3 >> myPoly2Sym([54010],y) ans= 5*y^4+4*y^3+ y >>myPoly2Sym([2 10000],z) ans 2*z^5 + z^4 2. Write a function that converts light-years to miles. Your function should take as input a numerical value representing the number of light-years. Your function should then convert this value to miles, and return the result as its output. It should also print the result of the conversion in the format shown below. Your function should make sure that the input is nonnegative. If the input is negative, an error message should be displayed, your output variable should be returned as Not a Number as shown in class, and your function should return carly. Examples of expected input and output: >>ly2mi(1) 1 light-year 5879000000000 mi./nans = 5.8790e+12 >> ly2mi(5) 5 light-year =29395000000000 mi. ans= 2.9395e+13 3. Revisit Practice Problem #3 from Lecture #7 where we used subfunctions to implement the quadratic equation. Let's say that your colleague attempted to convert the subfunctions implementation into a normal function implementation that could work not only on scalar values but also vectors. The result is below, but it has many errors. Debug the code and get it working, commenting each line you found a bug and how you fixed it. You should submit your solution as a function file. function x1,x2 = my quadratic func(a b c) d = sqrt(b^2-4*a*c); x1 = (-b+d)/(2*al); x2 = (-b-d).* (2*a);

Question image 1Question image 2