<?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 fit special polynomial - how to input coefficients? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600567#M80397</link>
    <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;Im plotting data using Fit Y by X.&lt;/P&gt;&lt;P&gt;I would like to plot a pre-known quadratic as a reference line (rather than fitting one to the data shown). I can see how this would be done for a linear fit using Fit Special, linear, then constrain the intercept and slope to what ever values, but when selecting quadratic (or higher orders) from the drop down box it doesnt give you somewhere to input the extra coefficients to constrain.&lt;/P&gt;&lt;P&gt;Can I do it via script instead and if so what would the format be?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jun 2023 16:36:19 GMT</pubDate>
    <dc:creator>Jumble</dc:creator>
    <dc:date>2023-06-08T16:36:19Z</dc:date>
    <item>
      <title>fit special polynomial - how to input coefficients?</title>
      <link>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600567#M80397</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;Im plotting data using Fit Y by X.&lt;/P&gt;&lt;P&gt;I would like to plot a pre-known quadratic as a reference line (rather than fitting one to the data shown). I can see how this would be done for a linear fit using Fit Special, linear, then constrain the intercept and slope to what ever values, but when selecting quadratic (or higher orders) from the drop down box it doesnt give you somewhere to input the extra coefficients to constrain.&lt;/P&gt;&lt;P&gt;Can I do it via script instead and if so what would the format be?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:36:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600567#M80397</guid>
      <dc:creator>Jumble</dc:creator>
      <dc:date>2023-06-08T16:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: fit special polynomial - how to input coefficients?</title>
      <link>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600572#M80398</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;A possible low-tech solution would be to compute your reference curve in a separate column in your data table and then plot it with the rest of the data.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;TS&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 19:04:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600572#M80398</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2023-02-13T19:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: fit special polynomial - how to input coefficients?</title>
      <link>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600598#M80402</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right-clicking on the graph, select "Customize" from the context menu, click the "+" icon. From here you can add a script using the Y function ( ) function, which takes 2 arguments: an expression (the function) and the domain variable (here, x).&lt;/P&gt;
&lt;P&gt;Click OK and you're done.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="brady_brady_1-1676320436311.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/50107iB31936D9E325C26B/image-size/large?v=v2&amp;amp;px=999" role="button" title="brady_brady_1-1676320436311.png" alt="brady_brady_1-1676320436311.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is also easy to do via scripting with the Y function ( ) function. Here, y = 2x^2 + 3x -5, corresponding to coefficients [2, 3, -5]&amp;nbsp; is plotted. I've used Horner's rule here, as it makes things easier in the next illustration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = astable(J(40,2,randominteger(-20,20)));

gb = dt &amp;lt;&amp;lt; Graph Builder( Variables( X( :Col2 ), Y( :Col1 ) ), Elements( Points( X, Y, Legend( 3 ) ) ) );

report(gb)[framebox(1)] &amp;lt;&amp;lt; add graphics script ( Y Function( (2 * x + 3) * x - 5, x ) );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One issue is that the coefficients might be determined at runtime, might not be integers, and the degree of the polynomial might be unknown. In this case something like the following will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = astable(J(40,2,randominteger(-20,20)));

gb = dt &amp;lt;&amp;lt; Graph Builder(
	Variables( X( :Col2 ), Y( :Col1 ) ),
	Elements( Points( X, Y, Legend( 3 ) ) ),
);

// get random uniform coefficient matrix 
coef = J(5, 1, randomuniform());

// build an expression using Horner's rule:
for each ( {v, i }, coef,// i = 1; v = coef[i];
	if (i  &amp;gt; 1, 
		fctExp = insert ( insert ( expr ( multiply ( ) ), nameExpr ( fctExp ) ), expr ( x ) );
	,
		fctExp = expr ( 0 );
	);
	fctExp = insert ( insert ( expr( add ( ) ), nameexpr( fctExp ) ), v );	
);

// substitute into a graph script expressison and evaluate
graphAdd = expr (
	report(gb)[framebox(1)] &amp;lt;&amp;lt; add graphics script ( Y Function( _EXPRESSION_ , x ) )
);

eval ( substitute ( nameexpr(graphAdd), expr( _EXPRESSION_ ), nameexpr ( fctExp ) ) );

//show the expression in the log
show ( fctExp )

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="brady_brady_0-1676320226114.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/50105iD4A8873C0F4344E0/image-size/large?v=v2&amp;amp;px=999" role="button" title="brady_brady_0-1676320226114.png" alt="brady_brady_0-1676320226114.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 20:35:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/600598#M80402</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2023-02-13T20:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: fit special polynomial - how to input coefficients?</title>
      <link>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/601339#M80469</link>
      <description>&lt;P&gt;Your initial suggestion of adding a script via the customize function worked. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 10:40:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/fit-special-polynomial-how-to-input-coefficients/m-p/601339#M80469</guid>
      <dc:creator>Jumble</dc:creator>
      <dc:date>2023-02-15T10:40:27Z</dc:date>
    </item>
  </channel>
</rss>

