Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting Quadratic Equation

    Hi, My son is learning Quadratic Equation and I am trying using Stata to help him.

    But before help him, First, I need help myself.

    Suppose we want to solve the following equation and Bhaskara's is here to help us on that

    The equation -5x² + 240x + 5000 = 0 has 2 real roots when solved:

    Code:
    . di ((-240)-((240)^2-4*(-5)*5000)^(1/2))/(2*(-5))
    63.698866
    
    . di ((-240)+((240)^2-4*(-5)*5000)^(1/2))/(2*(-5))
    -15.698866
    double checked with : https://coolconversion.com/math/quad...ion-calculator

    however when plotting using:

    Code:
    twoway (function (-(5*x)^2)+(240*x)+5000, range(-20 20)),yline(0) xline(0)
    the plot crosses the X axis in ~-10 and ~+20, when Y=0


    Click image for larger version

Name:	Capturar.PNG
Views:	1
Size:	54.8 KB
ID:	1717451


    Am I using the appropriate function to plot it ?

  • #2
    Originally posted by Luis Pecht View Post
    Am I using the appropriate function to plot it ?
    This works for me:
    Code:
    mata: st_matrix("Roots", Re(polyroots( (5000, 240, -5) )))
    graph twoway function y = -5 * x * x + 240 * x + 5000, range(-20 70) ///
        yline(0) xline(`=Roots[1, 1]' `=Roots[1, 2]')

    Comment


    • #3
      great, Joseph!! thks.

      Comment


      • #4
        Your graph command has a different function:
        Code:
        twoway (function (-(5*x)^2)+(240*x)+5000, range(-20 20)),yline(0) xline(0)
        
        //  should be 
         twoway (function (-5*x^2)+(240*x)+5000, range(-20 20)),yline(0) xline(0)
        By putting the (-5*x) in parentheses, you were squaring the -5, so you had a quadratic coefficient of 25 instead of -5. The fact that the graph showed an inverted parabola instead of an upright one is a clue that it was showing you the wrong function.

        Comment


        • #5
          Yes, Prof Clyde, Joseph simplify things in #2, using:

          Code:
          twoway (function (-5*x*x)+(240*x)+5000, range(-20 70)),yline(0) xline(0)

          thks,

          Comment

          Working...
          X