I need to write a script file that takes the coefficients of a quadratic and calculates the roots after testing them so that the least amount of calculation is done?

3 ビュー (過去 30 日間)
Brittany
Brittany 2014 年 7 月 29 日
回答済み: John 2014 年 7 月 29 日
I have started with a code to simply calculate two roots of a quadratic function:
function [x1, x2] = quadraticRoots(a, b, c)
% Function to calculate the roots of the quadratic equation:
% a*x^2 + b*x + c = 0
% USAGE: [x1, x2] = quadraticRoots(a, b, c)
% INPUTS: a, b and c - the three coefficients
% OUTPUTS: x1 and x2 - the two roots of the equation
s = sqrt(b^2 - 4*a*c);
x1 = (-b+s)/(2*a);
x2 = (-b-s)/(2*a);
but don't know where to go from here?

回答 (1 件)

John
John 2014 年 7 月 29 日
By "testing" them do you mean to check if the coefficients will produce a Real solution as opposed to a complex solution?

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by