A-man Posted August 8, 2012 Share Posted August 8, 2012 Is it possible to do math with complex numbers in SCAR? I want to make a mandlebrot visualizer, but I'm unsure how to do the math. About half way down the page here is an example with C/C++ of what I'm looking to achieve. http://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions/ Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted August 8, 2012 Share Posted August 8, 2012 I suppose you could roll your own type and create a few functions to do the basic stuff like add, subtract, multiply. Wouldn't be that tough. Not sure about performance. Quote Link to comment Share on other sites More sharing options...
FHannes Posted August 8, 2012 Share Posted August 8, 2012 Is it possible to do math with complex numbers in SCAR? I want to make a mandlebrot visualizer, but I'm unsure how to do the math. About half way down the page here is an example with C/C++ of what I'm looking to achieve. http://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions/ You could make a mandelbrot in SCAR, but it will probably be fairly slow due to the script engine. As Bixby noted, for complex numbers, you'll have to define a record type and some functions to perform operations. Quote Link to comment Share on other sites More sharing options...
MarkD Posted August 9, 2012 Share Posted August 9, 2012 As far as I know, SCAR isn't really meant for calculations like these. C++ would be a far better language to write it in. SCAR has some functions dealing with polar points and cartesian points, normal sine functions and other basic math stuff. PASCAL has a way to deal with complex numbers, I've found a demo about that below: program ComplexOperationsDemo; var z1, z2: Complex; Len, Angle: Real; begin z1 := Cmplx (2, 1); WriteLn; WriteLn ('Complex number z1 is: (', Re (z1) : 1, ',', Im (z1) : 1, ')'); WriteLn; z2 := Conjugate(z1); { GPC extension } WriteLn ('Conjugate of z1 is: (', Re (z2) : 1, ',', Im (z2) : 1, ')'); WriteLn; Len := Abs (z1); Angle := Arg (z1); WriteLn ('The polar representation of z1 is: Length=', Len : 1, ', Angle=', Angle : 1); WriteLn; z2 := Polar (Len, Angle); WriteLn ('Converting (Length, Angle) back to (x, y) gives: (', Re (z2) : 1, ',', Im (z2) : 1, ')'); WriteLn; WriteLn ('The following operations operate on the complex number z1'); WriteLn; z2 := ArcTan (z1); WriteLn ('ArcTan (z1) = (', Re (z2), ', ', Im (z2), ')'); WriteLn; z2 := z1 ** 3.141; WriteLn ('z1 ** 3.141 =', Re (z2), ', ', Im (z2), ')'); WriteLn; z2 := Sin (z1); WriteLn ('Sin (z1) = (', Re (z2), ', ', Im (z2), ')'); WriteLn ('(Cos, Ln, Exp, SqRt and Sqr exist also.)'); WriteLn; z2 := z1 pow 8; WriteLn ('z1 pow 8 = (', Re (z2), ', ', Im (z2), ')'); WriteLn; z2 := z1 pow (-8); WriteLn ('z1 pow (-8) = (', Re (z2), ', ', Im (z2), ')'); end. However, z1 and z2 are of type 'Complex', which doesn't exist in SCAR. I'm not sure why it doesn't, but you could make it work by creating the type. Quote Link to comment Share on other sites More sharing options...
FHannes Posted August 9, 2012 Share Posted August 9, 2012 As far as I know, SCAR isn't really meant for calculations like these.C++ would be a far better language to write it in. SCAR has some functions dealing with polar points and cartesian points, normal sine functions and other basic math stuff. PASCAL has a way to deal with complex numbers, I've found a demo about that below: program ComplexOperationsDemo; var z1, z2: Complex; Len, Angle: Real; begin z1 := Cmplx (2, 1); WriteLn; WriteLn ('Complex number z1 is: (', Re (z1) : 1, ',', Im (z1) : 1, ')'); WriteLn; z2 := Conjugate(z1); { GPC extension } WriteLn ('Conjugate of z1 is: (', Re (z2) : 1, ',', Im (z2) : 1, ')'); WriteLn; Len := Abs (z1); Angle := Arg (z1); WriteLn ('The polar representation of z1 is: Length=', Len : 1, ', Angle=', Angle : 1); WriteLn; z2 := Polar (Len, Angle); WriteLn ('Converting (Length, Angle) back to (x, y) gives: (', Re (z2) : 1, ',', Im (z2) : 1, ')'); WriteLn; WriteLn ('The following operations operate on the complex number z1'); WriteLn; z2 := ArcTan (z1); WriteLn ('ArcTan (z1) = (', Re (z2), ', ', Im (z2), ')'); WriteLn; z2 := z1 ** 3.141; WriteLn ('z1 ** 3.141 =', Re (z2), ', ', Im (z2), ')'); WriteLn; z2 := Sin (z1); WriteLn ('Sin (z1) = (', Re (z2), ', ', Im (z2), ')'); WriteLn ('(Cos, Ln, Exp, SqRt and Sqr exist also.)'); WriteLn; z2 := z1 pow 8; WriteLn ('z1 pow 8 = (', Re (z2), ', ', Im (z2), ')'); WriteLn; z2 := z1 pow (-8); WriteLn ('z1 pow (-8) = (', Re (z2), ', ', Im (z2), ')'); end. However, z1 and z2 are of type 'Complex', which doesn't exist in SCAR. I'm not sure why it doesn't, but you could make it work by creating the type. Actually, I'm fairly sure that in "pascal", these are just record record types with operator overloading, so it's nothing you can't implement in SCAR with some tinkering. Quote Link to comment Share on other sites More sharing options...