BookmarkSubscribeRSS Feed
Ksharp
Super User

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.

9 REPLIES 9
Hutch_sas
SAS Employee

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;

stat_sas
Ammonite | Level 13

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

Rick_SAS
SAS Super FREQ

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

Ksharp
Super User

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

Rick_SAS
SAS Super FREQ

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;

Ksharp
Super User

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 ?

Rick_SAS
SAS Super FREQ

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.

Ksharp
Super User

Thanks Doctor Rick Wicklin , and PG . I learn a lot from you guys.

Regards

Xia Keshan

PGStats
Opal | Level 21

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

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 9 replies
  • 1518 views
  • 0 likes
  • 5 in conversation