<?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: display a function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791514#M5752</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
_x=do(-2,2,0.05);
_y=_x;
x=expandgrid(_x,_y);

z=j(nrow(x),3,.);
do i=1 to nrow(x);
z[i,1]=(-20)*(exp(-0.2*sqrt(0.5*(x[i,1]**2+x[i,2]**2))))-
(exp(0.5*(cos(2*4*atan(1)*x[i,1])+cos(2*4*atan(1)*x[i,2]))))+exp(1)+20;
z[i,2:3]=x[i,];
end;
create in_graph from z [colname={'z' 'x' 'y'}];
append from z;
close;
run;

/* From Rick's post at:                                     */
/* http://blogs.sas.com/content/iml/create-surface-plot-sas */
proc template;                        /* surface plot with continuous color ramp */
define statgraph SurfaceTmplt;
dynamic _KMS _AGE _Z _Title;              /* dynamic variables */

 begingraph;
 entrytitle _Title;                   /* specify title at run time (optional) */
  layout overlay3d / tilt=30
          xaxisopts=(label="x")
          yaxisopts=(label="y" linearopts=(tickvaluelist=(-2 -1 0 1 2 )))
          zaxisopts=(label="z" linearopts=(tickvalueformat=xval.));
		  
  
    surfaceplotparm x=_KMS y=_AGE z=_Z /  /* specify variables at run time */

       name="surface" 
       surfacetype=fill
       colormodel=threecolorramp      /* or =twocolorramp */
       colorresponse=_Z 
       reversecolormodel=true;
    continuouslegend "surface";

    
  endlayout;
endgraph;
end;
run;

/* And... Render the Hat! */
proc sgrender data=in_graph template=SurfaceTmplt; 
   dynamic _KMS='X' _AGE='Y' _Z='Z' _Title="3D graph";
format Z percent7.1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a1.png" style="width: 867px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67604i721AE91E6DCBA5D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="a1.png" alt="a1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jan 2022 17:22:37 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2022-01-21T17:22:37Z</dc:date>
    <item>
      <title>display a function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791501#M5751</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to display a graph with the ackley function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*ackley function*/
y=(-20)*(exp(-0.2*sqrt(0.5*(x[1]**2+x[2]**2))))-(exp(0.5*(cos(2*4*atan(1)*x[1])+cos(2*4*atan(1)*x[2]))))+exp(1)+20;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this, I will use g3d, g3grid and maybe gcontour.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first step is to create the data statement in order to have x, y and z.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have : z=y*x&lt;/P&gt;&lt;P&gt;then the form of x and y must be similar than the form of the table sashelp.lake&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, I need x and y from an uniform law.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have code the beginning in IML:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc iml;
xmax=2;
xmin=-2;
range=xmax-xmin;
Y=j(range,1,0);
X=j(range,1,0);
X1=j(range*range,1,0);
do i=1 to range;
	call randgen(u,'uniform');
	Y[i,1]=xmin+u*range;
end;

do i=1 to range/2;
	y=y//y;
end;

do i=1 to range;
	call randgen(u1,'uniform');
	X[i,1]=xmin+u1*range;
end;

do i=1 to range;
	do n=1 to range*range;
		X1[n,1]=X[i,1];
	end;
end;
print X1;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;At the end, I have the correct Y but, I don't get the correct form of X which is like :&lt;/P&gt;&lt;P&gt;range times the first value, range times the second, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 16:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791501#M5751</guid>
      <dc:creator>CerditoSalvaje</dc:creator>
      <dc:date>2022-01-21T16:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: display a function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791514#M5752</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
_x=do(-2,2,0.05);
_y=_x;
x=expandgrid(_x,_y);

z=j(nrow(x),3,.);
do i=1 to nrow(x);
z[i,1]=(-20)*(exp(-0.2*sqrt(0.5*(x[i,1]**2+x[i,2]**2))))-
(exp(0.5*(cos(2*4*atan(1)*x[i,1])+cos(2*4*atan(1)*x[i,2]))))+exp(1)+20;
z[i,2:3]=x[i,];
end;
create in_graph from z [colname={'z' 'x' 'y'}];
append from z;
close;
run;

/* From Rick's post at:                                     */
/* http://blogs.sas.com/content/iml/create-surface-plot-sas */
proc template;                        /* surface plot with continuous color ramp */
define statgraph SurfaceTmplt;
dynamic _KMS _AGE _Z _Title;              /* dynamic variables */

 begingraph;
 entrytitle _Title;                   /* specify title at run time (optional) */
  layout overlay3d / tilt=30
          xaxisopts=(label="x")
          yaxisopts=(label="y" linearopts=(tickvaluelist=(-2 -1 0 1 2 )))
          zaxisopts=(label="z" linearopts=(tickvalueformat=xval.));
		  
  
    surfaceplotparm x=_KMS y=_AGE z=_Z /  /* specify variables at run time */

       name="surface" 
       surfacetype=fill
       colormodel=threecolorramp      /* or =twocolorramp */
       colorresponse=_Z 
       reversecolormodel=true;
    continuouslegend "surface";

    
  endlayout;
endgraph;
end;
run;

/* And... Render the Hat! */
proc sgrender data=in_graph template=SurfaceTmplt; 
   dynamic _KMS='X' _AGE='Y' _Z='Z' _Title="3D graph";
format Z percent7.1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a1.png" style="width: 867px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67604i721AE91E6DCBA5D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="a1.png" alt="a1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791514#M5752</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-01-21T17:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: display a function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791520#M5753</link>
      <description>Thank you very much. Very helpful.</description>
      <pubDate>Fri, 21 Jan 2022 17:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791520#M5753</guid>
      <dc:creator>CerditoSalvaje</dc:creator>
      <dc:date>2022-01-21T17:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: display a function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791531#M5754</link>
      <description>&lt;P&gt;If you want to create points on a uniform grid, use &lt;A href="https://blogs.sas.com/content/iml/2014/06/09/generate-a-grid-of-points.html" target="_self"&gt;the EXPANDGRID function&lt;/A&gt;. If you want to create a surface plot, see&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2015/10/12/create-surface-plot-sas.html" target="_blank"&gt;Create a surface plot in SAS - The DO Loop&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dx = 0.1;
%let dy = 0.1;

proc iml;
xmin=-2;
xmax=2;
xLin = do(xmin, xmax, &amp;amp;dx);

ymin=-2;
ymax=2;
yLin = do(ymin, ymax, &amp;amp;dy);

grid = expandgrid(xLin, yLin);
x = grid[,1];
y = grid[,2];

/*ackley function*/
pi = constant('pi');
z = -20*(exp(-0.2*sqrt(0.5*(x##2+y##2)))) -
        (exp(0.5*(cos(2*pi*x)+cos(2*pi*y)))) + exp(1) + 20;

create Ackley var {x y z};
append;
close;
QUIT;

title "Quick Visualization";
proc sgplot data=Ackley;
scatter x=x y=y / colorresponse=z markerattrs=(symbol=SquareFilled size=14)
                  colormodel=ThreeColorRamp;
run;
&lt;BR /&gt;/* &lt;A href="https://blogs.sas.com/content/iml/2015/10/12/create-surface-plot-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2015/10/12/create-surface-plot-sas.html&lt;/A&gt; */
proc template;                        /* surface plot with continuous color ramp */
define statgraph SurfaceTmplt;
dynamic _X _Y _Z _Title;              /* dynamic variables */
 begingraph;
 entrytitle _Title;                   /* specify title at run time (optional) */
  layout overlay3d;
    surfaceplotparm x=_X y=_Y z=_Z /  /* specify variables at run time */
       name="surface" 
       surfacetype=fill
       colormodel=threecolorramp      /* or =twocolorramp */
       colorresponse=_Z;              /* prior to 9.4m2, use SURFACECOLORGRADIENT= */
    continuouslegend "surface";
  endlayout;
endgraph;
end;
run;
proc sgrender data=Ackley template=SurfaceTmplt; 
   dynamic _X='X' _Y='Y' _Z='Z' _Title="Ackley Function";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791531#M5754</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-01-21T17:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: display a function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791532#M5755</link>
      <description>&lt;P&gt;Wow, except for vectorizing the Ackley function, these programs are virtually identical, right down to the references! I don't think I've ever seen that before for a long program.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791532#M5755</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-01-21T17:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: display a function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791533#M5756</link>
      <description>Thank you, Rick.</description>
      <pubDate>Fri, 21 Jan 2022 17:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/display-a-function/m-p/791533#M5756</guid>
      <dc:creator>CerditoSalvaje</dc:creator>
      <dc:date>2022-01-21T17:42:35Z</dc:date>
    </item>
  </channel>
</rss>

