Note that there are some explanatory texts on larger screens.

plurals
  1. POsolve In Matlab a quadratic equation with very small coefficients
    primarykey
    data
    text
    <p>I'm implementing a code in matlab to solve quadratic equations, using the resolvent formula:</p> <p><img src="https://i.stack.imgur.com/JgsUN.gif" alt="enter image description here"></p> <p>Here´s the code:</p> <pre><code>clear all format short a=1; b=30000000.001; c=1/4; rdelta=sqrt(b^2-4*a*c); x1=(-b+rdelta)/(2*a); x2=(-b-rdelta)/(2*a); fprintf(' Roots of the polynomial %5.3f x^2 + %5.3f x+%5.3f \n',a,b,c) fprintf ('x1= %e\n',x1) fprintf ('x2= %e\n\n',x2) valor_real_x1= -8.3333e-009; valor_real_x2= -2.6844e+007; error_abs_x1 = abs (valor_real_x1-x1); error_abs_x2 = abs (valor_real_x2-x2); error_rel_x1 = abs (error_abs_x1/valor_real_x1); error_rel_x2 = abs (error_abs_x2/valor_real_x2); fprintf(' absolute_errorx1 = |real value - obtained value| = |%e - %e| = %e \n',valor_real_x1,x1,error_abs_x1) fprintf(' absolute_errorx2 = |real value - obtained value| = |%e - %e| = %e \n\n',valor_real_x2,x2,error_abs_x2) fprintf(' relative error_x1 = |absolut error / real value| = |%e / %e| = %e \n',error_abs_x1,valor_real_x1,error_rel_x1 ) fprintf(' relative_error_x2 = |absolut error / real value| = |%e / %e| = %e \n',error_abs_x2,valor_real_x2,error_rel_x2) </code></pre> <p>The problem I have is that it gives me an exact solution, ie for values ​​a = 1, b = 30000000,001 c = 1/4, the values ​​of the roots are:</p> <pre><code>Roots of the polynomial 1.000 x^2 + 30000000.001 x+0.250 x1= -9.313226e-009 x2= -3.000000e+007 </code></pre> <p>Knowing that the exact value of the roots of the polynomial are:</p> <pre><code>x1= -8.3333e-009 x2= -2.6844e+007 </code></pre> <p>Which gives me the following errors in the absolute and relative precision of the calculations:</p> <pre><code> absolute_errorx1 = |real value - obtained value| = |-8.333300e-009 - -9.313226e-009| = 9.799257e-010 absolute_errorx2 = |real value - obtained value| = |-2.684400e+007 - -3.000000e+007| = 3.156000e+006 relative error_x1 = |absolut error / real value| = |9.799257e-010 / -8.333300e-009| = 1.175916e-001 relative_error_x2 = |absolut error / real value| = |3.156000e+006 / -2.684400e+007| = 1.175682e-001 </code></pre> <p>My question is: Is there an optimum method to obtain the roots of a quadratic equation?, ie I can make changes to my code to reduce the relative error between the expected solution and the resulting solution?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload