View Full Version : Lscript and fractals

josleys

02-07-2004, 12:56 AM

Having worked in Ultrafractal for years, I am now exploring how Lightwave can do things for me.

I only just started studying Lscript yesterday, but to my horror, I found that it cannot handle complex numbers, which are the bread and butter of fractal algorithms.

Am I correct? If so, is there a known workaround?

Sorry if this is an obviousd questions, but I thought this forum was the best place to ask..

Jos Leys

moubctez

02-25-2004, 01:32 AM

Well, any computer language cannot handle complex numbers. :)

Here's the hint: use separate variables for real and imaginary.

As an example, Mandelbrot's set:

z --> z*z + c

z = x + i*y

z*z = x*x + 2*i*x*y + i*i*y*y = x*x - y*y + 2*i*x*y

z_real = x*x - y*y

z_imag = 2*x*y

finally:

new_z_real = z_real + c_real

new_z_imag = z_imag + c_imag

I hope it helps. :)

josleys

02-25-2004, 10:08 AM

Splitting into real and imaginary parts works for simple formulas, but how about a formula like:

(z^3+sin(3*z))/(log(z)+tan(z)) or anything as 'complex' as this..

These things can get very complicated!

Anyway, thanks for your input!

Jos

moubctez

02-25-2004, 01:14 PM

Here is a small bunch of hints:

sin(x+iy): re = sin(x)cosh(y); im = cos(x)sinh(y)

cos(x+iy): re = cos(x)cosh(y); im = -sin(x)sinh(y)

tg(x+iy): re = sin(2x)/(cos(2x)+cosh(2y)

im = sinh(2y)/(cos(2x)+cosh(2y))

where 're' is the real part, and 'im' is imaginary

I believe you can implement complex numbers in LScript in a way. Actually, I find your problem very challenging. If you give me the details, I am willing to help.

Also, here are some link, maybe you will find them useful:

Numerical Recipes, a book in PDF with examples:

http://www.numerical-recipes.com/index.html

Useful algorithms, including fractals:

http://astronomy.swin.edu.au/~pbourke/

Science world, including mathematics:

http://scienceworld.wolfram.com/

Cheers :)

josleys

02-25-2004, 01:37 PM

Yes, you are right, there are formulae for all complex functions to split into real and imaginary. However it is just too cumbersome to work it all out. One of my algorithms has the following:

M[1,1,1]=ta/2

M[1,1,2]=(ta*tab-2*tb+2*i*qu)/(2*tab+4)/zo

M[1,2,1]=(ta*tab-2*tb-2*i*qu)*zo/(2*tab-4)

M[1,2,2]=ta/2

M[2,1,1]=(tb-i*qu)/2

M[2,1,2]=(tb*tab-2*ta-i*qu*tab)/(2*tab+4)/zo

M[2,2,1]=(tb*tab-2*ta+i*qu*tab)*zo/(2*tab-4)

M[2,2,2]=(tb+i*qu)/2

which is the definition of two arrays. All variables are complex. I then need to repeatedly multiply the matrices and the inverse matrices. Can you imagine the complexity of continuously splitting into real and imaginary?

I do appreciate your interest...

Jos

Powered by vBulletin® Version 4.2.3 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.