Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 20th, 2004, 02:35 PM
ecit12's Avatar
ecit12 ecit12 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 411 ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 42 m 14 sec
Reputation Power: 7
Algorithm Help..

OS: Linux
Language: PHP

ok..
currently at work we have to calculate dataPoints between certain time values to approximate the values between.
so if I got my data at point 0 and the next data pont at 93, I need data points between 1 and 92.
to do that we use a certain formula... basic polynomial.. and a for loop..
however.. when we have to do it for yearly data.. it becomes too much for the server..

anyone know how to optimize??

right now our code looks like this
Code:
Code:
for(i=0;i<93;i++){
      x[i]=a0 +
      a1*i +
      a2*i*i  +
      a3*i*i*i;

} 

I know I can use pow(x,y) to calculate the squares..

Reply With Quote
  #2  
Old October 22nd, 2004, 01:19 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 8
Unusual looking polynomial, but how and ever. Time it to see where the biggest drain is, I'd try the following to speed it up:
Code:
x[0]=a0;
if (0<i) 
 {i2[1]=1;//i2 will be cached array of i squared values
  i3[1]=1;//i3 will be cached array of i cubed values
  for(i=2;i<93;i++)
   {i2[i]=i*i;
    i3[i]=i*i2[i];
   }
  x[1]=a0+a1+a2+a3;
  for(i=1;i<93;i++)
   {x[i]=a0+a1*i+a2*i2[i]+a3*i3[i];}
 }
Plenty of other options to speed it up further, the above should start by cutting out any repeated calculations etc. Don't know if you can speed up the array access etc or find a language that will do the matrix multiplication for you in an optimised way.

The next step I would take would be to look at calculating the difference between the consecutive items, x[t]-x[t-1], and that would, for a start, allow you to substitute two additions in place of a multiplications in the loop etc - for instance, consider calculating a1*i1, a2*i2, a3*i3 as (iteratively derived) arrays separately.

Hope this makes sense etc, good luck.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Algorithm Help..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT