Complex variable functions principle and
non-principle solution
A B C D update 2010-10-24
This is a real number calculator, complex number calculator.
You need to know javascript commands to use this file.

This file is written under MSIE 6.0   Document   Compare
complex number online reference 01   02   03   04   05
This file is personal home work. Output
may contain error. Please verify first.

This file has complex function source code. But can not promise they are all correct. Below has thirty test button on left column. [complex01] and [complex02] are input boxes. [complex output] is output for principle value. One-to-many function output to Box1. Non-principle value answer no confirmation. You need to verify first. 9803220737
Proof +1=-1. if know the mathematics rule leak hole, then one can "proof"


Below is complex function for add/subtract/multiply/division etc. non-math operation.
Brief complex01 complex02 complex output     function name
caddf(c1,c2)
csubf(c1,c2)
cmulf(c1,c2)
cdivf(c1,c2)
conjf(c1)
cnewf(r1,r2)
cabsf(c1)
csqrt(c1)
cmulr(c1,r2)
cargf(c1)
cpolr(c1)
cxryi(c1)
cnegf(c1)
cgetr(c1)
cgeti(c1)

  ;  
1 0 = delete function name, make room for output box 9804130942
Above is complex function for add/subtract/multiply/division etc. non-math operation.
Below is complex function, math operation, many-to-one. no need to use +2*n*PI 9803161014
complex01=c1 in function name, complex02=c2 in function name.
Brief complex01 complex02 complex output     function name
cexpi(c1)
cexpf(c1)
csinf(c1)
ccosf(c1)
ctanf(c1)
csinh(c1)
ccosh(c1)
ctanh(c1)
cdotf(c1,c2)
dot product, complex separated by comma or ';' or blank
dot product use 〈u, v_conj〉, 〈u_conj, v〉 answer conjugate to each other.
cexpf('3i') = cexpi(3) no need to use "i", no need to use quote. 9805181224
cexpf('1+3i')=cexpi('1+3i') ; cexpf(2)=cexpi('2+0i')

Above function all not output to box1 below.
Below function all do output to box1 below.
Below is one-to-many functions, use +2*n*PI n is arbitrary integer. 9803151835
Brief complex01 complex02 principle output n=0    function name
clogf(c1,nBgn,nEnd)
cpowf(c1,c2,nB,nE)
casin(c1,rtsq01,nB,nE)
cacos(c1,rtsq01,nB,nE)
catan(c1,rtsq01,nB,nE)
asinh(c1,rtsq01,nB,nE)
acosh(c1,rtsq01,nB,nE)
atanh(c1,rtsq01,nB,nE)

Function argument is following
c1 and c2 are given (input) complex numbers.
rtsq01 determine square root take '+' (rtsq01!=1) or take '-' (rtsq01==1)
If omit rtsq01, default take '+' (root01=0)
nBgn,nEnd is n range in 2*n*PI [9803242228]
If omit nBgn,nEnd default n=0 to 0 for principle answer.
If assign nBgn and omit nEnd , return one value for n=nBgn
if assign both nBgn and nEnd , return n=[nBgn,nEnd] solution.
When return value is more than one, programmer need to use
manager function to arrange output for easy reading.
Otherwise ten complex number answer, twenty real/imag
numbers all string together.
This file has manager function, example clogfMan(clArg1)
and all function ...Man()

one-to-many function has +2*n*PI its n range

Box1, answer

Box2, equation doc.  


Below has "test box3 command" button, it is in fact 
a small calculator. Alert: complex add/subtract
and multiply/division are all carry out by functions
error (1+2*i)+(3+4*i) , correct caddf('1+2*i','3+4*i')
error (1+2*i)-(3+4*i) , correct csubf('1+2*i','3+4*i')
error (1+2*i)*(3+4*i) , correct cmulf('1+2*i','3+4*i')
error (1+2*i)/(3+4*i) , correct cdivf('1+2*i','3+4*i')
(1+2*i) is error, '1+2*i' is correct. 9803161923

Use search engine search for next string
Operator Overloading In Javascript
http://blog.thejit.org/2009/01/27/why-not-operator-overloading-in-javascript/
This page explain why-not-operator-overloading-in-javascript
For complex number c1,c2 we can not use c3=c1+c2
must use c3=caddf(c1,c2).
Box3 default:[sin(1+2i)^2+cos(1+2i)^2] Box4 should get: 1+0i

click to run MSIE 6.0
Examples
RUN 19 ; 51+ are big
Box3, JS command /*=*/ stop print; //^ add blank line

written under MSIE 6.0
Box4, output for Box3  

Box5, debug output ;  

 

<a name="online01">
complex number online resources
2003-07-02-21-21 received qccalc.exe
http://freeman2.us/qccalc.zip
2009-03-12-20-53 open
http://mathforum.org/library/drmath/sets/college_complex.html
2009-03-17-11-12 index page
http://personal.maths.surrey.ac.uk/st/C.Wulff/Modules/MS224/
2009-03-17-11-15
http://personal.maths.surrey.ac.uk/st/C.Wulff/Modules/MS224/cvch1.pdf
2009-03-21-19-19 Freeman access complex calculator
http://www.greuer.de/JavaScriptComplexCalc.html
2009-03-21-19-39 Freeman access complex calculator
http://www.twopaths.com/Calculator/CALCZ.EXE
<a name=JSMathFunc>
<a name="doc78">
update 2010-09-21 document
2010-09-21-19-50 start
This file complex2.htm initially 
intend to be demonstration for 
complex functions. See the page 
structure testSet 1, 2, 3.

<a name="doc79">
Wrote code and in/output boxes
to test complex functions. Later
find out the test structure can
be used as real number calculator, 
complex number calculator.
complex2.htm use javascript to
find answer. If need the value 
of one variable, for example abc,
user put 'abc' in one code line.
<a name="doc80">
complex2.htm convert box3 value
[[
var abc=sin(PI/3)
abc
]]
to
[[
var abc=sin(PI/3)
boxd14.value+="abc"  +"\n";
boxd14.value+=abc
boxd14.value+="\n";
]]
<a name="doc81"> Examples
run this code, output to box4.
[[
abc
0.8660254037844386
]]
Several version of complex2.htm 
remain this method.
<a name="doc82">
Earlier version use the criterion
that in a line, it has '=' or not?
If a line has '=', complex2.htm 
do NOT insert [boxd14.value+=]
otherwise, complex2.htm insert.
This simple method is good for
complex2.htm author personal use,
it is awkward for other to use.
<a name="doc83">
For example, code
[[
i=12
if(i<5)
  {
 i++
  }
else
  {
 i--;
  }
i
]]
<a name="doc84">
must write as
[[
i=12
if(i<5) { dummy=0
 i++;  dummy=0 }
else { dummy=0
 i--;  dummy=0 }
i
]]
to bring in '='.

<a name="doc85">
update 2010-09-21 has big change 
at function evalAll() not rely 
upon '=' only. Main point is to 
use javascript 
var keyword=... //9908190809
complex2.htm check variable name 
against keyword list. Now one
code line one 'else' is safe.
User no need to insert dummy=0
any more. But complex2.htm is
<a name="doc86"> Examples
not complete compatible with
javascript. For example,
var aa=sin(PI/5); 
both complex2.htm & javascript OK
But, same code split to 3 lines
 aa 
 =  
 sin(PI/5);
javascript OK, complex2.htm error.

<a name="doc87">
Updated complex2.htm can not find
 !true
answer. Reason is
 !true //WHY not print: no variable
Older version ('=' criterion) give
answer
[[
 !true
false
]]

<a name="doc88">
complex2.htm is like a seesaw.
When I see it, complex2.htm saw it.
When I saw it, complex2.htm see it.
Make up and raise one end, the other 
end falls. Please do not blame on me,
since this seesaw phenomenon obeys
Heisenberg Uncertainty Principle.
Sigh!  //How to go around seesaw?

<a name="doc89">
Use javascript code as calculator
author need tell user how to write
code. There are example button from
0 to 15 for small example.
Button 51 (and + in future) is for
bigger example.
Example 51 was chosen from
freeman2.com/tute0050.htm#ch14b054
<a name="doc90">
Found that code at ch14b054 was
wrong. 2010-09-20 & 21 made 
correction. The new 'corrected'
code (complex2.htm button 51)
still NOT promise to be correct. 
Simply no other body proofread, 
no other similar program run for 
comparison.
2010-09-21-20-56 here

<a name="doc91"> Examples
update 2010-09-21 add copyf(arg1)
function. Help user to copy one 
array to second (different memory
location) array (not just alias)
Use copyf(arg1) with caution, it
eat out memory quickly if array 
is big.

<a name="doc92">
update 2010-09-21 fixed cnewf()
function. Older version must use
as  v1=cnewf(1,2) //OK
But v1=cnewf(3)   //wrong
and v1=cnewf('4') //wrong
now, all three OK.
Hope you like the calculator I
wrote. 
Liu,Hsinhan 2010-09-21-21-09 stop

<a name="doc93"> 
Next is six reasons of why not print.
You can find them at box5 after run 
an example. 2010-09-25-19-25

whyNotPrint=
' has keyword';  //9909201039
' inside if()';  //9909231748
' if \\n ()';    //9909240936
' line has [=]'; //9909201040
' no variable';  //9909201041
' has [++],[--]';//9909221122
'#manyLine1cmd=';//9909291154
' [=] follows '; //9909291539
2010-09-25-17-45 done spelling check

<a name="doc94"> Examples
2010-09-28-14-35 start
Now create example 52 code.
Example 52 is a real number, real 
value example.
Real number say that it is not 
complex number example.
Real value say that it is not a
toy example.

<a name="doc95"> 
Reference: Quaternions and Rotation
Sequences. ISBN 0-691-05872-5, 1998
by Jack B. Kuipers. (Abbr. as QRS)

<a name="doc96"> 
Example 52 input is a set of rotated
three dimensional coordinate system.
Output to Eular angles and quaternion.
Before rotation, the coordinate system
has simple three axis vectors, that is
"rotation" matrix be
 [1,0,0]
 [0,1,0]
 [0,0,1]
It is an identity matrix, no rotation 
at all.

<a name="doc97"> 
x0axis is COLUMN 1 [1,0,0] // not row
y0axis is COLUMN 2 [0,1,0] // not row
z0axis is COLUMN 3 [0,0,1] // not row

After rotation, the coordinate system
has user specified three axis vectors, 
that is (for example) //9909281442 here
ax=12 degree
ay= 8 degree
az=-6.5 degree
<a name="doc98"> Examples
Aerospace Rotation Sequence matrix is
 [0.983902,-0.112101,-0.139173]
 [0.139479, 0.968584, 0.205888]
 [0.111720,-0.221985, 0.968628]
//9909281515 here
What is the meaning of above 
rotation matrix? It is simple to
remember. 
<a name="doc99"> 
Before rotation
x0axis is old column 1
 [ 1
   0
   0]
After rotation
x1axis is new column 1
 [ 0.983902,
   0.139479,
   0.111720]
<a name="doc100"> 
Remind that x axis is a vector.
It has three components in 3-dim.
space. 
Similarly,
y1axis is new column 2
 [-0.112101,
   0.968584,
  -0.221985]
<a name="doc101"> 
z1axis is new column 3
 [-0.139173,
   0.205888,
   0.968628]
//9909281527 here
If you set different initial x,y,z 
angles, above vector number should 
be different. 
//9909281543 here
<a name="doc102"> 
The following do the reverse. That
is given rotation matrix (like above)
Find Eular angles and quaternion.
From rotation matrix to quaternion
use QRS page 169 four q equations.
//here goto code section. 9909281548
//9909281555 start
Next is from quaternion to Eular 
angles. QRS page 168 tan(psi),
sin(theta), tan(phi) equations.
//here goto code section. 9909281558

<a name="doc103"> Examples
Upto here, example 52 code is done.
Please goto example section, click
52 button. At top of code, you can
input x:roll, y:pitch, z:yaw angles
in degree. At the end of code, program
back to same numbers which confirm
calculation. In middle, you get
rotation matrix and quaternion.
2010-09-28-16-20 stop

<a name="doc104"> 
2010-09-28-19-08 start
Quaternion is also named as Euler's
Parameter. For example, Classical
Mechanics second edition, by
Herbert Goldstein, page 153 last
line. Page 153 and 165 have related
formula. LiuHH first time learned
as Euler's parameter at University
of Iowa in Professor Edward Haug's
<a name="doc105"> 
class. First time see Quaternion 
when read Rotations, Quaternions,
and Double Groups. by Simon L.
Altmann ISBN 0-486-44518-6 around
2006-Aug to 2007. After read and 
think found that Quaternion and
Euler's Parameter are one thing.
2010-09-28-19-19 stop

<a name="doc106"> 
update 2010-10-03 //update 2010-10-04
2010-09-29-20-35 start
2010-09-26 rewrite Chinese version
complex1.htm Read code carefully.
Found several error/bug. Change as
following
1)
When search for '//', exclude '://'
Time stamp is 9909271146.
<a name="doc107"> 
2)
delete '-1'
from if(keyIndex<keyword.length-1)
  to if(keyIndex<keyword.length)
so that last keyword 'with' can be
found. Time stamp is 9909281142
3)
If input string use digits
 +'freeman2.com/complex1.htm'
older version get error. Repair at
9909280550
<a name="doc108"> Examples
4)
If input like
[[
 aa 
 =  
 sin(PI/5); 
]]
Old version get error. Now fixed.
When read to 'aa', peek to future 
line, see if '=' is coming. If is
then not print aa value. The key
variable is manyLine1cmd. This
manyLine1cmd is wide spread.
<a name="doc109"> 
5)
If input like
[[
  aa=6.5+  
2-sin(PI/8)
]]
When read to '2-sin(PI/8)', program
look previous line, see if there is 
'+' at line end. If yes, not print
'2-sin(PI/8)' value. Code location
is   "if(i0>0) //9909291947"

<a name="doc110"> 
Plus few more minor changes.
This improved version is still not
complete compatible with javascript.
For example, example 15, there is
one line MUST insert /*=*/

<a name="doc111"> 
LiuHH can not take care all possible
cases. When you run your code, if 
get error alert, check box 5 code.
See which line should not print
value but the string [outString+=]
is inserted in your code. 
<a name="doc112">
To stop this insert, add five bytes 
at the trouble line. it is "/*=*/".
Because complex2.htm do not care
/* comment */ then '=' in "/*=*/"
is visible to complex2.htm. When 
see a '=', complex2.htm do not 
insert [outString+=]
2010-09-29-21-03 stop

<a name="doc113"> Examples
2010-09-29-21-11 start
update 2010-10-03 deleted document
from [a name="doc01"] 
  to [a name="doc77"]
Please goto complex2_20100726.htm
for old document.
Also see [a name="doc77"]

<a name="doc114">
update 2010-10-03 added example 52
and 53. 
Example 51 is complex number example
Example 52 is real number example
Example 53 is physics example

Example 51 is CSMC eqn.14.14
Example 52 is Euler Angle, quaternion
Example 53 is Kepler and Newton laws.
2010-09-29-21-16 stop

<a name="doc115">
2010-10-02-17-33 start
update 2010-10-03 allow Box3, JS command
use one line
//^  for insert one blank line at box4
//^//^  for insert two blank lines etc.
 //^ insert nothing, must begin from
     left end
LiuHH tried to insert code for blank 
line at box4, this [//^] method will do
the job. Example 53 use the string [//^].
2010-10-02-17-41 stop

<a name="doc116">
2010-10-04-07-51 start
update 2010-10-04 made the following 
two changes.
1) deleted "else" button. You can 
   find it at old page
   Newer version (reading) use key
   word table (look for 9908190809)
   and avoid to print the value of
   "else"
<a name="doc117">
2) added in-file stop point name.
   2010-10-03-22-33 read
   JavaScript-Bible-5e.pdf 
   chapter 17: Location and History
   Objects.
   2010-10-03-22-59 success use the 
   code line window.location.hash 
   Apply at [a name="doc77"] the 
   link of complex2_20100726.htm
2010-10-04-08-00 stop

<a name="doc118">
2010-10-18-10-32 start
update 2010-10-18 add an example
button "2^3=8" to show pow(a,b)
function.

update 2010-10-18 add 
Convert degree to radian document
Please click <a name=JSMathFunc>
and look for "9910180956".

<a name="doc119"> Examples
update 2010-10-18 add 
//How to go around seesaw?
//It is very easy. 
//Instead of the code
  !true
  (sin(PI/3)+cos(PI/3))/2
//write next code
var a1=!true
var a2=(sin(PI/3)+cos(PI/3))/2
a1
a2
//first two lines work in 
//complex2_20100726.htm
//last four lines work in
//complex2.htm
2010-10-18-10-42 stop

<a name="doc120">
2010-10-24-13-30 start
update 2010-10-24 add example button 19
which solve x^i=i where i=sqrt(-1)
2010-10-24-13-32 stop





Javascript index
http://freeman2.com/jsindex2.htm   local
Save graph code to same folder as htm files.
http://freeman2.com/jsgraph2.js   local


This file complex variable functions
Created on 2009-02-24
Chinese version first upload 2009-03-20
Chinese done version upload 2009-04-06
English version start translation on 2009-04-09-17-14
English version done translation on 2009-04-12-11-20

URL of this English page
http://freeman2.com/complex2.htm
2010-07-26 updated English page. local
http://freeman2.com/complex2_20100726.htm

URL of this Chinese page
http://freeman2.com/complex1.htm
URL of Chinese 2010-07-27 version
http://freeman2.com/complex1_990727.htm


Thank you for visiting Freeman's web site.
Freeman 2009-04-12-11-22