Find Roots of a Nonlinear Equation using SAS/IML

Here we discuss how to find roots of a Nonlinear Equation using SAS/IML let’s begin

Step 1. Define a function that has one or more zeros.

Step 2. Plot the function to get an idea of how many roots there are and approximately where they are located.

Step 3. Specify three intervals to search for roots using froot function.

proc iml;
/* define a function that has one or more zeros */
start Func(x);
return( exp(-x##2) - x##3 + 5#x +1 );
finish;

if num(symget("SYSVER"))>=9.4 then do;
/* plot the function to get an idea of how many roots there
are and approximately where they are located */
x = do(-4, 4, 0.1);
y = Func(x);
call Series(x, y)
grid="x" other="refline 0 / axis=y"; /* reference line */
end;

/* Specify three intervals to search for roots */
intervals = {-4 -1.5, /* 1st interval [-4, -1.5] */
-1.5 1 , /* 2nd interval [-1.5 1] */
1 4 }; /* 3rd interval [1, 4] */
Roots = froot("Func", intervals);
print Roots;
quit;

Result Output :

Roots
-2.127156
-0.383909
2.3304466

Graph Output :

Find Roots of a Nonlinear Equation using SAS/IML