My program to calculate roots works incorrectly?
Show older comments
I have the user input a, b, and c (of a quadratic equation) into a dialog box. the discriminate is calculated and if it's greater than 0, it should output "two roots", less than 0 "no roots", etc. However, everything I enter returns "no roots"
prompt={'enter a: ','Enter b: ','Enter c: '};
dlg_title='quadratic';
answer=inputdlg(prompt,dlg_title);
a = (answer{1});
b = (answer{2});
c = (answer{3});
D = b^2 - 4.*a.*c;
p = [a b c];
if D>0
disp('There are two roots')
r = roots(p)
elseif D<0
disp('There are no roots')
else
disp('There is one root')
r = roots(p)
end
any ideas how to fix it? I'm not very experience with matlab so I'm sure what I've done wrong.
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!