computing with a complex number

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
john
computing with a complex number

Post by john » Wed Aug 23, 2006 5:58 pm

how can i use i the square root of -1 in a qb programme

john

buff1

imaginary numbers

Post by buff1 » Thu Aug 24, 2006 1:41 am

Not handled by qb. Probably fortran would be the best bet unless someone else has an idea.

Guest

Post by Guest » Thu Aug 24, 2006 3:30 am

It all depends on how you want to use the square root of -1, or i, as it is usually called. If you post a few mathematical examples of what results you are looking for, I'm sure we can help you.

For instance, in ac electricity, i is used o define a complex number that can also be handled as a vector with an angle.

john page

computing wth complex numbers

Post by john page » Thu Aug 24, 2006 11:05 am

thank you for your replies, I'm looking at fractal images, from what I read last night in 'fractal cosmos' by Lifesmith you use the size or nomal value of
the term containing i plotted on the complex plane which is the distance from the Nul point in the the complex plane. I'm still trying to get my head round it. The size or norm is the length of the hypotenuse of the triangle outlined by the points plotted by the complex variable & the origin. As this length involves souares i becomes some value K*-1 & is always a real number..

Guest

Post by Guest » Fri Aug 25, 2006 9:52 pm

If you can post a few examples of your complex numbers, and what you expect as a result, I'm sure we can help you.

john page

computing with complex numbers

Post by john page » Sat Aug 26, 2006 2:36 pm

If I have a function say f(z)= z^2+c
where z=2+3i & c = 4+5i, i=(-1)^0.5
I would like to evaluate f(z) & plot the results
on the complex plane Thanks John

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Re: computing with complex numbers

Post by Ralph » Sat Aug 26, 2006 9:13 pm

john page wrote:If I have a function say f(z)= z^2+c
where z=2+3i & c = 4+5i, i=(-1)^0.5
I would like to evaluate f(z) & plot the results
on the complex plane Thanks John
First of all, please note that, in complex numbers, the imaginary square root of -1 is used as a special symbol to indicate a 90-degree direction of the y component, from the x component. Its use is as follows.

To evaluate your function, you would enter each of te two components of z and c, from z = x+iy, and c = a+ib, thus:

Code: Select all

x=2:y=3
a=4:b=5
z=sqr(x^2+y^2)
c=sqr(a^2+b^2)
Fz=z^2+c
'and, to show the final result
PRINT "F(z) =";Fz
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Guest

Post by Guest » Sun Aug 27, 2006 2:20 pm

Thank you Ralph I'm very grateful John

Guest

Post by Guest » Wed Aug 30, 2006 3:24 pm

Ok I've tried this before and the process is

c=a+ib
f(0)=c
f(1)=f(0)^2+c

so real f(1)=a^2-b^2+a
imag f(1) = 2*a*b +b

f(2)=f(1)^2+c

and you keep on doing this to see how quickly the function diverges.

Then choose a different value for c and repeat

Code: Select all

SCREEN 12
DEFINT I-K
FOR ix = 1 TO 640
FOR iy = 1 TO 480
cr = ix / 220 - 2
ci = iy / 160 - 1.5
WHILE (ABS(zoi) - ABS(ci) + ABS(zor) - ABS(cr) < 25) AND k < 128
znr = zor * zor - zoi * zoi + cr
zni = 2 * zoi * zor + ci
zor = znr: zoi = zni
k = k + 1
WEND
IF k < 8 THEN k = 1
k = k MOD 16
PSET (ix, iy), k
zoi = 0: zor = 0: k = 0
NEXT iy
NEXT ix
SLEEP

Post Reply