Logo by fractalwizz - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. April 20, 2024, 06:09:58 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: What software should I use to create exponential type functions?  (Read 4265 times)
Description: Basically I'd like to do Taylor series on the GPU
0 Members and 2 Guests are viewing this topic.
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« on: April 14, 2014, 05:10:10 PM »

  I'm running into a problem implementing the exponential function Taylor series expansion of sin and cosine in fragmentarium.  I've messed around with various forms, and think it has something to do with the low precision of the floats.

  My ancient GPU won't handle doubles anyway, but I was wondering which software I should use to implement my own exponential function variant.  

  Here is code (for a plain old exponential function expansion of sin and cosine- not the code that I want to implement) that SHOULD work in Fragmentarium, but doesn't for whatever reason:

Code:
vec2 special2(float an)
{
vec2 tot=(1.0,an);
vec2 temp=(0.0,0.0);
vec2 work=(0.0,an);

int i = 1;
float count=2.0;

while (i<63) {    //shouldn't need too many iterations
temp.x= -work.y*an/count;
temp.y= work.x*an/count;
work=temp;

count=count+1.0;
tot=tot+work;
i++;
}

return vec2(tot);

}
« Last Edit: April 14, 2014, 05:33:57 PM by M Benesi » Logged

Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #1 on: April 14, 2014, 07:21:40 PM »

 Here is code (for a plain old exponential function expansion of sin and cosine- not the code that I want to implement) that SHOULD work in Fragmentarium, but doesn't for whatever reason:


You just forgot to specify the 'vec2' constructor. Change to the following and it works:
Code:
	vec2 tot=vec2(1.0,an);
vec2 temp=vec2(0.0,0.0);
vec2 work=vec2(0.0,an);

Notice, that this approximation quickly breaks down for large arguments (here shown for n = 63), so you should constrain the argument to the primary branch using mod(...).



I also timed this, because I was curious. For n=63, the series approximation is roughly 8x slower, but for n=13 (which just covers the primary branch), the speed difference is only about 50%.
Logged
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #2 on: April 14, 2014, 11:31:22 PM »

  Thanks- that was driving me nuts, although I ignored the type cast warnings.

  I was already constraining it between -2 and 2 pi.  Finish this reply later- I have been summoned.
Logged

Roquen
Iterator
*
Posts: 180


« Reply #3 on: April 15, 2014, 09:05:33 AM »

Truncated series expansions are terrible cost vs. accuracy even if you could work with Reals (except in very small distance from the approximation point)...so they're pretty useless in practice.  What do you really want to approximate?
Logged

All code submitted by me is in the public domain. (http://unlicense.org/)
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #4 on: April 15, 2014, 10:29:16 PM »

  Thanks again Syntopia.  

  @Roquen-

  I wrote out a series that ends up adding all the later portions of the binomial series minus the first portions for a "special" type of sin/cosine variant (a and b are both imaginary).  Anyway, I didn't notice (pretty obvious now) that it ends up as...

   1 + \frac{(a+b)^1-a}{1!}+ \frac{(a+b)^2-a^2}{2!}+\frac{(a+b)^3-a^3}{3!}+\frac{(a+b)^4-a^4}{4!}+...

  cosine (a+b) - cosine (a)    and   sin (a+b) - sin (a)

  So, I actually don't need to do the series expansion now that I see the light... its nothing special, and doesn't result in anything great. 

« Last Edit: April 15, 2014, 10:52:51 PM by M Benesi » Logged

Pages: [1]   Go Down
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.192 seconds with 24 queries. (Pretty URLs adds 0.016s, 2q)