Without using the roots command, write a function to calculate roots of the quadratic equation

8 ビュー (過去 30 日間)
Without using the roots command, write a function to calculate roots of the quadratic equation
ax^2+bx+c=0
Inputs to the function should be the coefficients a, b and c and output should be the roots. Test your program by setting a=2,b=3,c=-1
can someone help me out with this? I cant think of anything but roots to use. would I have to use poly? or fzero?

採用された回答

Evan
Evan 2013 年 6 月 24 日
No need to call any built-in function. Just write your own using the quadratic formula.

その他の回答 (2 件)

Tom
Tom 2013 年 6 月 24 日
I'd recommend maths.

James Tursa
James Tursa 2013 年 6 月 24 日
You can use one of the formulations here:
The quadratic formula is listed, of course, but that is prone to cancellation error. So I would advise impressing your professor by coding up the algorithm under the "Avoiding loss of significance" section.
  2 件のコメント
Chris
Chris 2013 年 6 月 24 日
This confuses me still how do I add in an Algorithm? Im terrible at this matlab stuff. so would i have to put the original function in?
James Tursa
James Tursa 2013 年 6 月 25 日
It would be best if you could post what you have so far and then we can comment on it and suggest improvements. E.g., a function outline would be this (e.g., put in a file called quadratic_roots.m):
function [x1 x2] = quadratic_roots(a,b,c)
% add your code here to calculate x1 and x2
return
end

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by