In: Advanced Math
Design a Root Finding solver in Matlab that satisfies the
arguments below;
• Inputs will be coeficients of the equation.
• Outputs will be roots
• It should work with any polynomial
?=?0+?1?1+?2?2+?3?3+⋯+????
The below function gives you the roots of the any polynomial equation which is in the form of p1xn+...+pnx+pn+1=0.
Polynomial equations contain a single variable with nonnegative exponents.
r = roots(p) ------------- Predefined matlab function.
Where r is the root of the equation.
p is the column vector, which is the list of coeficients.
Case 1:
For example, create a vector to represent the polynomial x2−x−6, then calculate the roots.
p = [1 -1 -6]; r = roots(p)
r = 3 -2
By convention, matlab returns the roots in a column vector.
The poly function converts the roots back to polynomial coefficients.
p2 = poly(r)
p2 = 1 -1 -6
Case 2:
for a quadratic polynomial x4−1=0.
p = [1 0 0 0 -1]; r = roots(p)
r = 4×1 complex -1.0000 + 0.0000i 0.0000 + 1.0000i 0.0000 - 1.0000i 1.0000 + 0.0000i
Case 3 :
For example, find the values of θ that solve the equation.
3cos2(θ)−sin(θ)+3=0.
Use the fact that cos2(θ)=1−sin2(θ) to express the equation entirely in terms of sine functions:
−3sin2(θ)−sin(θ)+6=0.
Use the substitution x=sin(θ) to express the equation as a simple polynomial equation:
−3x2−x+6=0.
p = [-3 -1 6];
r = roots(p)
r =
-1.5907 1.2573
To resolve the substitution, use θ=sin−1(x). The asin function calculates the inverse sine.
theta = asin(r)
theta = -1.5708 + 1.0395i 1.5708 - 0.7028i