POV-Ray : Newsgroups : povray.beta-test : Functions more than 65535 : Re: Functions more than 65535 Server Time
29 Jul 2024 18:27:30 EDT (-0400)
  Re: Functions more than 65535  
From: Tor Olav Kristensen
Date: 14 May 2002 13:57:58
Message: <3CE14F6A.541E31CD@hotmail.com>

> 
> On Tue, 14 May 2002 10:29:54 +0200, "Thorsten Froehlich" <tho### [at] trfde>
> wrote:
> > It would have to return multiple results in some cases, which is not really
> > possible right now...
> 
> But knowing max order of polynomial I know max number of roots so can ask for
> n-th root. Additional function could return number of roots to check if there
> is any.

Funny that you should mention this now.

Since a few months after I started to use POV-Ray,
I have tried to make some macros that would do
matrix and polynomial calculations.

But the "Dangling pointer bug" made this work very
difficult.

But now that it is soon all gone, I have managed to
take these macros some further.

The code below shows how some of the polynomial
macros works as they are now.

If there is enough interest in these macros, then
maybe I'll take the time to make some documentation
or examples on how to use them.


Tor Olav



#declare RR = array[5] { -3, 4, 0, 5, 1/3 }
PrintRoots(RR, "x")
// ((x + 3)*(x - 4)*x*(x - 5)*(x - 0.333333))


// Assemble a polynomial from roots:

// ((x + 3)*(x - 4)*x*(x - 5)*(x - 0.333333))
#declare P0 = P_FromRoots(RR)
Print_P(P0, "x")
// (0 -20*x +62.333333*x^2 -5*x^3 -6.333333*x^4 +x^5)


// Find real roots of a polynomial:

// (0 -20*x +187/3*x^2 -5*x^3 -19/3*x^4 +x^5)
PrintRoots(R_RootsOf_P(array[6] { 0, -20, 187/3, -5, -19/3, 1 }), "x")
// (x*(x - 0.333333)*(x - 5)*(x - 4)*(x + 3))


// Multiply two polynomials:

// (x - 4)*(x - 1/3) 
#declare P1 = P_Mult(P_FromRoot(4), P_FromRoot(1/3))
Print_P(P1, "x")
// (1.333333 -4.333333*x +x^2)


// Divide one polynomial by another:

// (0 -20*x +187/3*x^2 -5*x^3 -19/3*x^4 +x^5)/(4/3 -13/3*x +x^2)
Print_P(P_Div(P0, P1), "x")
// (0 -15*x -2*x^2 + x^3)


// Differentiate a polynomial once:

// (2 -A +3*A^2 +A^3 +A^4)
#declare P2 = array[5] { 2, -1, 3, 1, 1 }
Print_P(P_Diff(P2, 1), "A")
// (-1 +6*A +3*A^2 +4*A^3)


// Integrate a polynomial twice:

// (-1 +6*A +3*A^2 +4*A^3)
#declare P3 = array[4] { -1, 6, 3, 4 }
Print_P(P_Int(P3, 2), "A")
// (0 -0.500000*A^2 +A^3 +0.250000*A^4 +0.200000*A^5)


// Assemble polynomial from a multiple root:

// (t - 2)*(t - 2)*(t - 2)*(t - 2)*(t - 2)
Print_P(P_FromRepeatedRoot(2, 5), "t")
// (-32 +80*t -80*t^2 +40*t^3 -10*t^4 +t^5)


// Make a Bernstein polynomial:

Print_P(P_Bernstein(1, 4), "y")
// ( 0 +4*y -12*y^2 +12*y^3 -4*y^4)


// Make a Fibonacci polynomial:

#declare PF = P_Fibonacci(7)
Print_P(PF, "u")
// (1 + 6*u^2 +5*u^4 +u^6)

#declare Fib7PolyFn = PolyFunction(PF)
#debug str(Fib7PolyFn(1), 0, 0)
// 13 // I.e. the 7th Fibonacci number


// And several other more or less useful polynomial macros
// together with a whole set of matrix calculation macros.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.