フィルターのクリア

Help with writing a program to find roots

2 ビュー (過去 30 日間)
Steven
Steven 2012 年 3 月 31 日
I need help making a function file that can find the roots of a polynomial.
For example I need to find the roots of 2x^2 + 10x + 12.
I've started off the function:
function p = findroots(a, b, c)
I dont know what else to put after, I've tried so many different ways.
PLEASE HELP.

採用された回答

Rick Rosson
Rick Rosson 2012 年 3 月 31 日
Please try:
function p = findroots(a,b,c)
d = sqrt(b^2 - 4*a*c);
p = (-b + [ -1 +1 ]*d) / (2*a);
end
Alternatively:
p = roots([ a b c ]);
HTH.
Rick
  1 件のコメント
Steven
Steven 2012 年 4 月 1 日
thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by