How do I get this function to accept one input argument, a vector representing the three coefficients of the quadratic in the order a, b, c?
古いコメントを表示
function[quadRoots, disc] = Q1(coeff)
%function solves quadratic equation in the form ax^2 + bx + c = 0
a= coeff(1,1);
b= coeff(2,1);
c= coeff(3,1);
end
%finding the descriminant
disc = (b^2-4*a*c);
%roots
if disc>0
x1= ((-b+sqrt(disc))/(2*a));
x2= ((-b-sqrt(disc))/(2*a));
quadRoots= [x1, x2]
end
%no real roots
if disc<0
quadRoots = nan;
end
%one real root
if disc == 0
x1= ((-b+sqrt(disc))/(2*a));
disc= (b^2-(4*a*c));
quadRoots - x1;
end
end
1 件のコメント
zhanel zhumagulova
2020 年 1 月 23 日
Trying to do the same question
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!