<?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 find roots of function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794659#M5787</link>
    <description>&lt;P&gt;I confused why i get 3.3 for root of function for froot call. I know function have root at x=1 because 1-4+2+1 = 0. So why froot call not give me root&amp;gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
start func(x);
return x**3 - 4*x**2 + 2*x + 1;
finish;

root = froot("func", {-4 4});
print root;
y = func(root);
print y;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 05 Feb 2022 11:06:49 GMT</pubDate>
    <dc:creator>WeiChen</dc:creator>
    <dc:date>2022-02-05T11:06:49Z</dc:date>
    <item>
      <title>find roots of function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794659#M5787</link>
      <description>&lt;P&gt;I confused why i get 3.3 for root of function for froot call. I know function have root at x=1 because 1-4+2+1 = 0. So why froot call not give me root&amp;gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
start func(x);
return x**3 - 4*x**2 + 2*x + 1;
finish;

root = froot("func", {-4 4});
print root;
y = func(root);
print y;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Feb 2022 11:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794659#M5787</guid>
      <dc:creator>WeiChen</dc:creator>
      <dc:date>2022-02-05T11:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: find roots of function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794661#M5788</link>
      <description>&lt;P&gt;The FROOT function returns one root within the interval that you specify. The value x=3.3 is a root, just not the one that you want!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how can you find the other roots? Read the article, &lt;A href="https://blogs.sas.com/content/iml/2015/06/22/root-guess.html" target="_self"&gt;"Finding roots: Automating the search for an initial guess."&lt;/A&gt;&amp;nbsp;It suggests graphing the function on a domain that is wide enough to display all the roots. FOr your function, I converted the formula to use the '#' multiplication operator so that I can pass in a vector of x values with one call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
/* vectorize computation so that x can be a vector */
start func(x);
   return x##3 - 4*x##2 + 2#x + 1;
finish;

/* Graph function on wide domain. See
   https://blogs.sas.com/content/iml/2015/06/22/root-guess.html
*/
x = do(-2, 4, 0.1);
y = func(x);
call scatter(x, y) grid={x y};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot58.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68239iD387958E22321211/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot58.png" alt="SGPlot58.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt; From the graph, it looks like you can subdivide the x axis into nonoverlapping intervals so that there is one root in each interval. The FROOT function will then compute the three roots of this function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intervals = {-4 0,
              0 2,
              2 4};
roots = froot("func", intervals);    
y = func(roots);
print roots y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure IML: roots_y" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;roots&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;y&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;-0.302776&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3.3027756&lt;/TD&gt;
&lt;TD class="r data"&gt;1.776E-15&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sat, 05 Feb 2022 11:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794661#M5788</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-02-05T11:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: find roots of function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794663#M5789</link>
      <description>&lt;P&gt;What if i dont know how many roots are in function?&lt;/P&gt;</description>
      <pubDate>Sat, 05 Feb 2022 11:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794663#M5789</guid>
      <dc:creator>WeiChen</dc:creator>
      <dc:date>2022-02-05T11:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: find roots of function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794664#M5790</link>
      <description>&lt;P&gt;Read the article. It discusses that situation.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Feb 2022 11:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794664#M5790</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-02-05T11:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: find roots of function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794668#M5791</link>
      <description>&lt;P&gt;Rick,&lt;/P&gt;
&lt;P&gt;It is about&amp;nbsp;to find the roots of the polynomial .Shouldn't use&amp;nbsp;POLYROOT()?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
p={1 -4 2 1};
r=polyroot(p);
print r;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1644070372211.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68240i013704AB57BA4F34/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1644070372211.png" alt="Ksharp_0-1644070372211.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Feb 2022 14:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794668#M5791</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-05T14:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: find roots of function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794681#M5792</link>
      <description>&lt;P&gt;Yes, POLYROOT would work for this example. It wasn't clear to me whether the OP was actually interested in a polynomial or was interested in a harder problem and is using the polynomial as an example.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Feb 2022 20:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/find-roots-of-function/m-p/794681#M5792</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-02-05T20:59:53Z</dc:date>
    </item>
  </channel>
</rss>

