This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-11-01 19:41:54

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Complex number calculators

I'm working on some complex number calculators --- didn't know  how to program in exponentiation and logarithms with Scratch.


If you don't know what arguments are, they are just angles on the complex plane. To make that clearer, the argument of a complex number a+bi is just the angle to the positive part of the real axis if you draw a line to the point (a,b)=a+bi on the complex plane. For example, the argument of 3i is 90 degrees.

Offline

 

#2 2012-11-01 19:45:57

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

I meant that I might use the word argument later on in my discussion.

Offline

 

#3 2012-11-01 20:23:15

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Complex number calculators

I think any expnentation (pardon me for bad spelling  tongue ) would be

<(x) * (x)>
And just add however many times you need it.

And 100log is 10, right?

So any log equation would be <(x)/(10)>


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#4 2012-11-01 22:20:01

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Complex number calculators

mythbusteranimator wrote:

I think any expnentation (pardon me for bad spelling  tongue ) would be

<(x) * (x)>
And just add however many times you need it.

And 100log is 10, right?

So any log equation would be <(x)/(10)>

Actually, that's not what log does. Log100 is 2.
That's sorta like saying 5$ is 13, so $ means add 8. $ could be an operation for *2+3 or *3-2, etc.

Also, you can't just multiply a complex number as a real number, you have to treat it like a binomial.

Other than that, I'd like to help (a bit)

Offline

 

#5 2012-11-02 00:11:00

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Just so you know, exponentiation is often extended like this:


a^-b=1/a^b
a^(1/2)=sqrt(a), the square root of a,
a^(1/3)=cbrt(a), the cube root of a,
and in general,
a^(1/n)=nroot(a), the nth root of a, and
e^(iradians)=cos(radians)+sin(radians)*i. The principal value of ln(a) is defined to be ln(radians)=ln(|radians|)+iarg(radians) where ln(a)=b if e^b=a (if a>0 and b is a real number), |a+bi|=sqrt(a^2+b^2), and arg(a) is the argument of a (restricted  to -pi<arg(a)<=pi radians). (a<=b means a is less than or equal to b)
Now, we can use the exponential laws. Just in case you don't know, they are:

a^(b+c)=a^b*a^c,
a^(b-c)=a^b/a^c, and
a^(bc) sad a^b)^c.

And the change of base formula tells us how to find principal logarithms in any base:

log a base b=ln(a)/ln(b)

Also log a base b=c if b^c=a and log a base b=1/log b base a (assuming all logarithms are included). So a^(b/n)=a^(1/n*b) sad a^(1/n))^b=nroot(a)^b, and a^(b+ci) sad e^n(a))^(b+ci)=e^(ln(a)*(b+ci))=e^((ln(|a|)+iarg(a))(b+ci)). Now the (ln(|a|)+iarg(a))(b+ci) can be solved with FOIL. (ln(|a|)+iarg(a))(b+ci)=ln(|a|)b+iln(|a|)c+iarg(a)b+i^2*ln(c)=ln(|a|)b+iln(|a|)c+iarg(a)b-ln(c)=ln(|a|)-ln(c)+i*arg(a)b+i*ln(|a|)c. So, that means a^(b+ci)=e^((ln(|a|)-ln(c))+i(arg(a)b+ln(|a|)c)=e^(ln(|a|)-ln(c))*e^(i(arg(a)b+ln(|a|)c)=e^(ln(|a|)-ln(c))*(cos(arg(a)b+ln(|a|)c)+i*sin(arg(a)b+ln(|a|)c)) neutral a|/c*(cos(arg(a)b+ln(|a|)c)+i*sin(arg(a)b+ln(|a|)c)) neutral a|/c*(cos(arg(a)b+ln(|a|)c))+|a|/c*(i*sin(arg(a)b+ln(|a|)c)). The fact that this and the formula for logarithms uses arguments of complex numbers is the problem.

Offline

 

#6 2012-11-02 00:14:13

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Sorry, the smilies should be off. I'll go change that if I can.

Offline

 

#7 2012-11-02 00:29:55

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

It should have been:

Just so you know, exponentiation is often extended like this:


a^-b=1/a^b
a^(1/2)=sqrt(a), the square root of a,
a^(1/3)=cbrt(a), the cube root of a,
and in general,
a^(1/n)=nroot(a), the nth root of a, and
e^(iradians)=cos(radians)+sin(radians)*i. The principal value of ln(a) is defined to be ln(radians)=ln(|radians|)+iarg(radians) where ln(a)=b if e^b=a (if a>0 and b is a real number), |a+bi|=sqrt(a^2+b^2), and arg(a) is the argument of a (restricted  to -pi<arg(a)<=pi radians). (a<=b means a is less than or equal to b)
Now, we can use the exponential laws. Just in case you don't know, they are:

a^(b+c)=a^b*a^c,
a^(b-c)=a^b/a^c, and
a^(bc)=(a^b)^c.

And the change of base formula tells us how to find principal logarithms in any base:

log a base b=ln(a)/ln(b)

Also log a base b=c if b^c=a and log a base b=1/log b base a (assuming all logarithms are included). So a^(b/n)=a^(1/n*b)=(a^(1/n))^b=nroot(a)^b, and a^(b+ci)=(e^n(a))^(b+ci)=e^(ln(a)*(b+ci))=e^((ln(|a|)+iarg(a))(b+ci)). Now the (ln(|a|)+iarg(a))(b+ci) can be solved with FOIL. (ln(|a|)+iarg(a))(b+ci)=ln(|a|)b+iln(|a|)c+iarg(a)b+i^2*ln(c)=ln(|a|)b+iln(|a|)c+iarg(a)b-ln(c)=ln(|a|)-ln(c)+i*arg(a)b+i*ln(|a|)c. So, that means a^(b+ci)=e^((ln(|a|)-ln(c))+i(arg(a)b+ln(|a|)c)=e^(ln(|a|)-ln(c))*e^(i(arg(a)b+ln(|a|)c)=e^(ln(|a|)-ln(c))*(cos(arg(a)b+ln(|a|)c)+i*sin(arg(a)b+ln(|a|)c))=|a|/c*(cos(arg(a)b+ln(|a|)c)+i*sin(arg(a)b+ln(|a|)c))=|a|/c*(cos(arg(a)b+ln(|a|)c))+|a|/c*(i*sin(arg(a)b+ln(|a|)c)). The fact that this and the formula for logarithms uses arguments of complex numbers is the problem.

Offline

 

#8 2012-11-02 00:53:56

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

If we key in a=e, we get e^(b+ci) neutral e|/c*(cos(arg(e)b+ln(|e|)c))+|e|/c*(i*sin(arg(e)b+ln(|e|)c))=e/c*(cos(b+c))+e/c*(i*sin(b+c)) and it follows that e^(b+ci)=e^b*e^(ci)=e^b*cos(c)+e^b*isin(c). Does that mean that e/c*(cos(b+c))+e/c*(isin(b+c))=e^b*cos(c)+e^b*isin(c)? I'm not quite sure if I did my math right ...  yikes

Offline

 

#9 2012-11-02 00:57:28

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Sorry again, it should have not started out as e^(b+ci) neutral , but e^(b+ci) neutral

Offline

 

#10 2012-11-02 01:01:29

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Oh, sorry again! It should have started out as e^(b+ci)=|. The :o was supposed to be a smilie.

Offline

 

#11 2012-11-02 19:10:23

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Is there any way to find angles with Scratch? That would help me a lot.

Offline

 

#12 2012-11-02 19:21:41

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Complex number calculators

wiz99903 wrote:

Is there any way to find angles with Scratch? That would help me a lot.

Find angles? As in two lines intersecting?


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#13 2012-11-02 19:31:41

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Yes. We need that in the formula for complex number exponentiation formula. e.g. (1+i)^(3+4i). Also, complex arguments (remember) are defined by angles.

Offline

 

#14 2012-11-02 19:34:49

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Because you can't just multiply 1+i by itself 3+4i times. That would be insane.

Offline

 

#15 2012-11-02 20:34:21

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

So, see my post. It's #7.

Offline

 

#16 2012-11-02 21:34:17

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

It tells you how to find the Exponential (sorry for the capitalization of the word) of a complex number.

Offline

 

#17 2012-11-02 21:37:44

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

And also any expression of the form (a+bi)^(c+di).

Offline

 

#18 2012-11-02 23:30:09

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

I know that the argument of cos(k)+isin(k) has arguments (there are multiple) of the form k+2mΠ radians. (Yes, I have my character mapper. Also, it's only true if m is an integer.)

Offline

 

#19 2012-11-02 23:33:15

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

I just didn't use it before.

Offline

 

#20 2012-11-02 23:39:33

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

I meant the character mapper.

Offline

 

#21 2012-11-07 18:24:40

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

Yes. We can get the principal argument if we use the formula arg(cos(x)+isin(x))=x if -Π<x<=Π. Any multiple like 1, 2, 3, etc. but not 1+i, 3+4i, i, -i, 2i, 5+5i, -1, -2, 5, -10, 0 etc. has the same argument.

Offline

 

#22 2012-11-07 18:51:34

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

but can you do that with repeats, or with what?

Offline

 

#23 2012-11-07 19:08:23

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

wiz99903 wrote:

Because you can't just multiply 1+i by itself 3+4i times. That would be insane.

Insane, like you could compute 3^.5 by multiplying? Thatt's (again, I'm not too strict about my spelling) not possible.

Offline

 

#24 2012-11-07 19:17:06

wiz99903
New Scratcher
Registered: 2012-10-23
Posts: 53

Re: Complex number calculators

that's right, you just can't. but you can cmpute (recall that i'm not too strict abuot my spelling) 3^.5 as sqrt(3), 9^(3+4i) as e^(ln(9)*(3+4i)) and then e^(ln(9)*3+ln(9)*4i) and then 9^3*cos(4ln(9))+i9^3*sin(4ln(9)) and then 729cos(4ln9)+729isin(4ln9).

Offline

 

#25 2012-11-07 20:03:57

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Complex number calculators

Never mind. I don't find it assuring to work with someone who knows he's doing something wrong, purposely does not fix it, and tells all of us instead.

Offline

 

Board footer