<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Real roots of degree 3 Polynomial in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50637#M28788</link>
    <description>&lt;P&gt;You can use this &lt;A href="https://math.vanderbilt.edu/schectex/courses/cubic/" target="_self"&gt;formula &lt;/A&gt;to get the first root, substitute that x value into the expression&amp;nbsp;to reduce the polyomial orrder to 2, and the use the quadratic soltution to obtain the remaining roots.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2018 14:40:52 GMT</pubDate>
    <dc:creator>Mark_Bailey</dc:creator>
    <dc:date>2018-02-02T14:40:52Z</dc:date>
    <item>
      <title>Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50634#M28785</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN&gt;Does anyone know how&lt;/SPAN&gt;&lt;/SPAN&gt; to calculate real roots of degree 3 polynomial with JMP scripting ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have &lt;SPAN&gt;the coefficients&lt;/SPAN&gt; of the equation :&amp;nbsp; 0 = A + B.X + C.X² + DX^3. What I need is the real solutions.&lt;/P&gt;&lt;P&gt;I started to create a new data table with lots of rows in order to get as close as possible to the desired value, but it takes too much time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 14:34:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50634#M28785</guid>
      <dc:creator>MHz</dc:creator>
      <dc:date>2018-02-02T14:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50637#M28788</link>
      <description>&lt;P&gt;You can use this &lt;A href="https://math.vanderbilt.edu/schectex/courses/cubic/" target="_self"&gt;formula &lt;/A&gt;to get the first root, substitute that x value into the expression&amp;nbsp;to reduce the polyomial orrder to 2, and the use the quadratic soltution to obtain the remaining roots.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 14:40:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50637#M28788</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2018-02-02T14:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50700#M28812</link>
      <description>&lt;P&gt;Thank you for this answer.&lt;/P&gt;&lt;P&gt;It's indeed a way of doing, but I'm affraid that won't work everytime I will use the script : the square root of a negative number is the reason why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Excel I'm able to do it, but not on JMP, and I rather prefer not to use two softwares for one script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have another way of doing it?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 08:19:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50700#M28812</guid>
      <dc:creator>MHz</dc:creator>
      <dc:date>2018-02-05T08:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50709#M28817</link>
      <description>&lt;P&gt;Maybe the Minimize() function can help.Since it find the minimum, rather than the zero, you have to transform your cubic so the zero is at the minimum.&amp;nbsp;Presumably squaring is better than absolute value because the Minimum function says it will take derivatives.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;f = Expr( Power( -2 - 3 * x + 5 * Power( x, 2 ) + Power( x, 3 ), 2 ) );
x = -100;
minFromLeft = Minimize( Name Expr( f ), {x} );
xFromLeft = x;
x = 100;
minFromRight = Minimize( Name Expr( f ), {x} );
xFromRight = x;
show(xFromLeft, minFromLeft, xFromRight, minFromRight);

// result:
xFromLeft = -5.5995441248061;
minFromLeft = 1.07130883787516e-10;
xFromRight = 0.276987650239635;
minFromRight = 2.4771578468284;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Searching from the left and the right if you know such bounds should find at least one real root, and with that the problem becomes quadratic.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 14:48:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50709#M28817</guid>
      <dc:creator>XanGregg</dc:creator>
      <dc:date>2018-02-05T14:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50716#M28822</link>
      <description>&lt;P&gt;The minimize function seems a good way of doing it, but I cannot make it work :&lt;/P&gt;&lt;P&gt;I've tried your script, but at the row 3 ( &amp;nbsp; &lt;SPAN&gt;minFromLeft &lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Minimize&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Name Expr&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN&gt; f &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;x&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; &amp;nbsp; )&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following alert :&lt;/P&gt;&lt;P&gt;"Optimization failed: Failed: Cannot Decrease Objective Function"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've the JMP version 10.0.0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN&gt;Does it have anything to do with that?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 16:18:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50716#M28822</guid>
      <dc:creator>MHz</dc:creator>
      <dc:date>2018-02-05T16:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50728#M28828</link>
      <description>Likely there have been improvements since JMP 10. You might try experimenting with the parameters, such as the tolerance.</description>
      <pubDate>Mon, 05 Feb 2018 19:02:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50728#M28828</guid>
      <dc:creator>XanGregg</dc:creator>
      <dc:date>2018-02-05T19:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50730#M28829</link>
      <description>&lt;P&gt;(Not a mathematician, I'm sure this has some flaws...) Similar to your original idea, but make JSL do the work. I'm pretty sure Minimize has seen some improvements since JMP 10.&amp;nbsp;&lt;A href="https://community.jmp.com/t5/JMPer-Cable/Minimize-and-Maximize-Functions-in-JSL/ba-p/36355/jump-to/first-unread-message" target="_blank"&gt;https://community.jmp.com/t5/JMPer-Cable/Minimize-and-Maximize-Functions-in-JSL/ba-p/36355/jump-to/first-unread-message&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a = -2;
b = -3;
c = 5;
d = 1;

f = Function( {x},
    a + b * x + c * x * x + d * x * x * x
);

lo = -1e99;
hi = 1e99;
vlo = f( lo );
vhi = f( hi );
v = 1;
nn=0;
While( (abs(v)&amp;gt;1e-15)  ,
    test = (lo + hi) / 2;
    v = f( test );

    If( v &amp;gt; 0,
        If(
            vhi &amp;gt; 0, hi = test,
            vlo &amp;gt; 0, lo = test
        ),
        If(
            vhi &amp;lt; 0, hi = test,
            vlo &amp;lt; 0, lo = test
        )

    );
);


New Window( "Example",
    Graph Box(
        X Scale( -10, 10 ),
        Y Scale( -30, 30 ),
        Pen Color( "red" );
        Y Function( f(x), x );
        pencolor("black");
        V Line( test );
        hline(0);
    )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Found a zero" style="width: 427px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/9195iFC3F77AD5A5B1EAB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Found a zero" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Found a zero&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If the coefficients on the ^2 and ^3 terms are too big, you'll need to make the -1e99 to 1e99 interval smaller.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 19:46:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50730#M28829</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-05T19:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50753#M28840</link>
      <description>&lt;P&gt;I tried both Minimize() and&amp;nbsp;the Nonlinear platform. Both works well to solve polynomials, but&amp;nbsp;it's easy to miss one or more roots because of a bad initial value. Looking at the graph helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have R installed you could try this JSL function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
// Function calling R, returns real roots of polynomials
// Input: a matrix of coefficients [x^0 ... x^n] 
realroots = Function({p},
    R Init();
    R Send(p);
    R Submit("roots=polyroot(p); real=Re(roots[which(round(Im(roots),12)==0)])");
    real = R Get(real);
    R Term();
    real;
);

// Try it!
p1 = [-4 0 1];  // two real roots: ±2^2=4  
p2 = [-27 0 0 1];  // one real root: 3^3=27  
p3 = [7 -8 4 1]; // one real root
p4 = [1 -3 1 1]; // three real roots
ex1 = realroots(p1);
ex2 = realroots(p2);
ex3 = realroots(p3);
ex4 = realroots(p4);
Show(ex1, ex2, ex3, ex4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 22:28:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50753#M28840</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2018-02-05T22:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Real roots of degree 3 Polynomial</title>
      <link>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50772#M28855</link>
      <description>&lt;P&gt;I've selected the answer that works for me with my JMP version.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 13:11:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Real-roots-of-degree-3-Polynomial/m-p/50772#M28855</guid>
      <dc:creator>MHz</dc:creator>
      <dc:date>2018-02-06T13:11:32Z</dc:date>
    </item>
  </channel>
</rss>

