Quadratic equation & Minus B
Show older comments
How do I solve the quadratic equation ax^2+bx+c=0 using the minus b formula, x=-b+- sqrt b^2-4ac/2a on MATLAB
Thank you
3 Comments
Geoff Hayes
on 15 May 2019
Fergal - are a, b, and c known? If so, wouldn't the code just be
x1 = (-b + sqrt(b^2 - (4 * a * c))) / (2 * a);
x2 = (-b - sqrt(b^2 - (4 * a * c))) / (2 * a);
assuming a is not zero...
Fergal Ahern
on 15 May 2019
Edited: Fergal Ahern
on 15 May 2019
James Tursa
on 15 May 2019
To read coefficients from the keyboard, you could use the input function
To see if a number is real, you could use the isreal function
Accepted Answer
More Answers (1)
Pavi thra
on 28 Oct 2020
0 votes
a1 = 'Enter value of a ';
a = input(a1)
b1= 'Enter value of b ';
b = input(b1)
c1= 'Enter value of c ';
c = input(c1)
x1 = (-b + sqrt(b^2 - (4 * a * c))) / (2 * a);
x2 = (-b - sqrt(b^2 - (4 * a * c))) / (2 * a);
t1=isreal(x1);
t2=isreal(x2);
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!