Creating output for quadradic roots that displays i if imaginary

1 回表示 (過去 30 日間)
dylan stephens
dylan stephens 2021 年 2 月 26 日
回答済み: Swetha Polemoni 2021 年 3 月 2 日
I am trying to get this to display the imaginary values with an i after them in the output. Any suggestions?
function quadroots(a,b,c)
%function to calculate the roots of a quadratic function given a, b, c
%2/25/21
%AE 227
z=discrim(a,b,c);
if z<0
z=z*-1;
end
w1=(-b+sqrt(z))/(2*a);
w2=(-b-sqrt(z))/(2*a);
fprintf('The roots are: %.0f, %.0f.\n',w1,w2);
end

回答 (1 件)

Swetha Polemoni
Swetha Polemoni 2021 年 3 月 2 日
Hi
You may find Matlab "roots" useful to find roots of quadratic equation.

カテゴリ

Help Center および File ExchangePattern Recognition and Classification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by