## How to stop quadratic formula calculator from giving inverse outputs?

Hi, I’m doing a worksheet based around matlab which involved solving quadratic formulas. I probably overcomplicated it and now made a calculator that keeps giving the inverse of my expected answer, could anyone help please?

for k = 1 : 7

disp ( ‘ For the equation ax^2 + bx + c ‘ )

a = input ( ‘ Enter a; ‘ );

b = input ( ‘ Enter b; ‘ );

c = input ( ‘ Enter c; ‘ );

D = ( b^2 ) – ( 4 * a * c );

if D < 0

fprintf ( ‘ n The equation has no real roots . nn ‘)

elseif D == 0

root = -b / ( 2 * a );

fprintf ( ‘ nThe equation has one root, n ‘ )

fprintf ( ‘ %.7fnn ‘ , root )

else

r1 = ( – b + sqrt ( D ) ) / ( 2 * a ) ;

r2 = ( – b – sqrt ( D ) ) / ( 2 * a ) ;

fprintf ( ‘n The equation has two roots, n ‘ )

fprintf ( ‘ %.7f and %.7fnn ‘ , r1 ,r2 )

end

end

For the equation ax^2 + bx + c

Enter a;

1

Enter b;

9

Enter c;

14

The equation has two roots,

-2.0000000 and -7.0000000

For the equation ax^2 + bx + c

Enter a;

1

Enter b;

-3

Enter c;

-18

The equation has two roots,

6.0000000 and -3.0000000Hi, I’m doing a worksheet based around matlab which involved solving quadratic formulas. I probably overcomplicated it and now made a calculator that keeps giving the inverse of my expected answer, could anyone help please?

for k = 1 : 7

disp ( ‘ For the equation ax^2 + bx + c ‘ )

a = input ( ‘ Enter a; ‘ );

b = input ( ‘ Enter b; ‘ );

c = input ( ‘ Enter c; ‘ );

D = ( b^2 ) – ( 4 * a * c );

if D < 0

fprintf ( ‘ n The equation has no real roots . nn ‘)

elseif D == 0

root = -b / ( 2 * a );

fprintf ( ‘ nThe equation has one root, n ‘ )

fprintf ( ‘ %.7fnn ‘ , root )

else

r1 = ( – b + sqrt ( D ) ) / ( 2 * a ) ;

r2 = ( – b – sqrt ( D ) ) / ( 2 * a ) ;

fprintf ( ‘n The equation has two roots, n ‘ )

fprintf ( ‘ %.7f and %.7fnn ‘ , r1 ,r2 )

end

end

For the equation ax^2 + bx + c

Enter a;

1

Enter b;

9

Enter c;

14

The equation has two roots,

-2.0000000 and -7.0000000

For the equation ax^2 + bx + c

Enter a;

1

Enter b;

-3

Enter c;

-18

The equation has two roots,

6.0000000 and -3.0000000 Hi, I’m doing a worksheet based around matlab which involved solving quadratic formulas. I probably overcomplicated it and now made a calculator that keeps giving the inverse of my expected answer, could anyone help please?

for k = 1 : 7

disp ( ‘ For the equation ax^2 + bx + c ‘ )

a = input ( ‘ Enter a; ‘ );

b = input ( ‘ Enter b; ‘ );

c = input ( ‘ Enter c; ‘ );

D = ( b^2 ) – ( 4 * a * c );

if D < 0

fprintf ( ‘ n The equation has no real roots . nn ‘)

elseif D == 0

root = -b / ( 2 * a );

fprintf ( ‘ nThe equation has one root, n ‘ )

fprintf ( ‘ %.7fnn ‘ , root )

else

r1 = ( – b + sqrt ( D ) ) / ( 2 * a ) ;

r2 = ( – b – sqrt ( D ) ) / ( 2 * a ) ;

fprintf ( ‘n The equation has two roots, n ‘ )

fprintf ( ‘ %.7f and %.7fnn ‘ , r1 ,r2 )

end

end

For the equation ax^2 + bx + c

Enter a;

1

Enter b;

9

Enter c;

14

The equation has two roots,

-2.0000000 and -7.0000000

For the equation ax^2 + bx + c

Enter a;

1

Enter b;

-3

Enter c;

-18

The equation has two roots,

6.0000000 and -3.0000000 quadratic formula MATLAB Answers — New Questions