Homework MATLAB 3, 4 Problem 1 Solution

Homework MATLAB 3, 4 Problem 1 Solution
1250
EX:
Use MATLAB to solve for x in the following quadratic equation:
x 2 + 2x − 15 = 0
Recall the formula for the quadratic equation solution:
x=
−b ± b 2 − 4ac
2a
or, when a =1 (the coefficient of the x2 term), we have a simpler form:
2
b
⎛ b⎞
x=− ± ⎜ ⎟ −c
⎝ 2⎠
2
SOL'N:
>> a = 1;
% Coefficient of x^2 in polynomial
>> b = 2;
% Coefficient of x
in polynomial
>> c = -15; % Coefficient of x^0 in polynomial
>> discrim = sqrt(b^2 - 4*a*c) % square root term
discrim =
8
>> x1 = (-b+discrim)/(2*a) % 1st root
x1 =
3.0000
>> x2 = (-b-discrim)/(2*a) % 2nd root
x2 =
-5.0000