Shop OBEX P1 Docs P2 Docs Learn Events
X Squared Command — Parallax Forums

X Squared Command

ercoerco Posts: 20,256
edited 2011-04-02 13:51 in BASIC Stamp
Did I miss something, or is there not a squared command (X^2) or Y^X (Y to the Xth power) in PBasic?

Never needed it until now!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-04-02 11:39
    You can always do X*X for X2. Even with word-length results, though, YX would overflow so quickly, that it's usefulness would be pretty limited. What formula are you trying to compute? Maybe logarithms would be more useful to you, to keep the results in-bounds.

    -Phil
  • ercoerco Posts: 20,256
    edited 2011-04-02 13:51
    I'm doing quadratics with small numbers, well within word variable limits. I'm just surprised that:

    a) there's not a PBasic command to do it, and
    b) I never noticed that in 17 years of using the Stamp!

    Thanks Phil. And here are my own personal thoughts on quadratics:

    Quadratic formulaA quadratic equation with real or complex coefficients has two solutions, called roots. These two solutions may or may not be distinct, and they may or may not be real.

    The roots are given by the quadratic formula


    where the symbol "±" indicates that both

    and

    are solutions of the quadratic equation.

    There is also a shortened version of the quadratic formula which is commonly used when the coefficient of x is an even number:


    In this case the solutions are given by:


    [edit] Discriminant
    Example discriminant signs
    ■ <0: x2+1⁄2
    ■ =0: −4⁄3x2+4⁄3x−1⁄3
    ■ >0: 3⁄2x2+1⁄2x−4⁄3In the above formula, the expression underneath the square root sign is called the discriminant of the quadratic equation, and is often represented using an upper case Greek delta, the initial of the Greek word Διακρίνουσα, Diakrínousa, discriminant:


    A quadratic equation with real coefficients can have either one or two distinct real roots, or two distinct complex roots. In this case the discriminant determines the number and nature of the roots. There are three cases:

    If the discriminant is positive, then there are two distinct roots, both of which are real numbers:
    and

    For quadratic equations with integer coefficients, if the discriminant is a perfect square, then the roots are rational numbers—in other cases they may be quadratic irrationals.
    If the discriminant is zero, then there is exactly one distinct real root, sometimes called a double root:

    If the discriminant is negative, then there are no real roots. Rather, there are two distinct (non-real) complex roots, which are complex conjugates of each other:
    and

    where i is the imaginary unit.
    Thus the roots are distinct if and only if the discriminant is non-zero, and the roots are real if and only if the discriminant is non-negative.

    [edit] Geometry
    For the quadratic function:
    f (x) = x2 − x − 2 = (x + 1)(x − 2) of a real variable x, the x-coordinates of the points where the graph intersects the x-axis, x = −1 and x = 2, are the solutions of the quadratic equation: x2 − x − 2 = 0.The solutions of the quadratic equation


    are also the roots of the quadratic function:


    since they are the values of x for which


    If a, b, and c are real numbers and the domain of f is the set of real numbers, then the roots of f are exactly the x-coordinates of the points where the graph touches the x-axis.

    It follows from the above that, if the discriminant is positive, the graph touches the x-axis at two points, if zero, the graph touches at one point, and if negative, the graph does not touch the x-axis.
Sign In or Register to comment.