I want compute such formula. How could I get it ?
10= 1.2*(1+ x ) + 1.2*(1+ x )**2 + 1.2*(1+ x )**3 + 1.2*(1+ x )**4
I want x= ?
Thanks.
For a 4th degree poynomial there will be generally 4 complex solutions. Looks like the polyroot() function is what you need, check the IML documentation. I suggest you first compute z = polyroot( {1.2 1.2 1.2 1.2 -10) to get the imaginary roots, then since z = 1 + x, x = z-1, just subtract 1 from the first column of z to get x, i. e.
proc iml;
a = {1.2 1.2 1.2 1.2 -10};
z = polyroot(a);
x = z - {1 0,1 0,1 0,1 0};
print x;
Hi,
If you take 1.2 as a common above equation becomes
10=1.2{(1+x) + (1+x)**2 + (1+x)**3 + (1+x)**4}
10 = 1.2[{1-(x+1)**5}/{1-(x+1)} as a result of geometric series in (1+x)
and more simplified form is
1.2(x+1)**5 - 10x - 1=0
Hope this helps.
Thanks
If you want only the real roots on a bounded interval, use the FROOT function. See A simple way to find the root of a function of one variable - The DO Loop
Thanks Hutch@sas stat@sas Rick Wicklin . I just suppose SAS can give me a simple code to get X like Hutch@sas did .
Sorry .I can't mark it as answered , because I can't find that button .
Regrads
Xia Keshan
Here is the program from the blog post. I replaced the function in the post with the example that you give:
proc iml;
start Func(x);
fx = 1.2*(1+ x) + 1.2*(1+ x)##2 + 1.2*(1+ x)##3 + 1.2*(1+ x)##4;
return(fx - 10); /* find x where f(x)=10 */
finish;
intervals = {-4 -1, /* 1st interval [-4, -1] */
-1 1}; /* 2nd interval [-1, 1] */
z = froot("Func", intervals);
print z;
Thanks Doctor Rick Wicklin ,
I think I should start to learn IML in near future .
I also can get it by brutally enumerate the X value . right ?
Well, sort of. If you want a DATA step solution, there are ways that are better than enumeration. You can use the bisection method. Do an internet search and you'll find DATA step implementations of the bisection method, such as this one: http://analytics.ncsu.edu/sesug/2007/PO21.pdf The key is that these algorithms find the "zeros" (or roots) so you want to solve for the roots of f(x)-10=0.
You could hijack proc nlin to do the job:
data test;
y = 10;
run;
proc nlin data=test;
parms x 0;
model y = 1.2*(1+ x ) + 1.2*(1+ x )**2 + 1.2*(1+ x )**3 + 1.2*(1+ x )**4 ;
run;
PG
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.