Solver ARITHMETIC on Complex Numbers
Algebra
->
Algebra
->
Complex Numbers Imaginary Numbers Solvers and Lesson
-> Solver ARITHMETIC on Complex Numbers
Log On
Ad:
Algebrator™
solves your algebra problems and provides step-by-step explanations!
Ad:
Algebra Solved!™
: algebra software solves algebra homework problems with step-by-step help!
Algebra: Complex Numbers
Solvers
Lessons
Answers archive
Quiz
In Depth
Source code of 'ARITHMETIC on Complex Numbers'
This Solver (ARITHMETIC on Complex Numbers)
was created by by
ichudov(499)
:
View Source
,
Show
,
Put on YOUR site
About ichudov
:
I am not a paid tutor, I am the owner of this web site.
==section input Evaluate *[input a_real=2] + *[input a_imag=1]i *[choice operation + - * /] *[input b_real=2] + *[input b_imag=1]i. ==section solution perl my $result; sub signed { my $a = shift @_; return $a if $a < 0; $a =~ s/^(\d)/+$1/; return $a; } if ( $operation eq '+' ) { $r_real = $a_real + $b_real; $r_imag = $a_imag + $b_imag; print "$r_real ".signed( $r_imag)."i.<P> <B>Solution:</B>Addition of two complex numbers <CODE>a + bi</CODE> and <CODE>c+di</CODE> is done according to formula:<P> <CENTER>(a + bi) + (c+di) = (a+c) + (b+d)i.</CENTER> In our case, {{{ ($a_real + $a_imag*i) + ($b_real + $b_imag*i) = ($a_real+$b_real) + ($a_imag+$b_imag)*i = $r_real+$r_imag*i}}}."; } elsif ( $operation eq '-' ) { $r_real = $a_real - $b_real; $r_imag = $a_imag - $b_imag; print " <B>Solution:</B>Subtraction of two complex numbers <CODE>a + bi</CODE> and <CODE>c+di</CODE> is done according to formula:<P> <CENTER><CODE>(a + bi) - (c+di) = (a+c) - (b+d)i.</CODE></center> In our case, {{{($a_real + $a_imag*i) - ($b_real + $b_imag*i) = ($a_real - $b_real) + ($a_imag-$b_imag)i = $r_real + $r_imag*i}}}"; } elsif ( $operation eq '*' ) { $r_real = $a_real * $b_real - $a_imag * $b_imag; $r_imag = $a_real * $b_imag + $a_imag * $b_real; print " <B>Solution:</B>Multiplication of two complex numbers <CODE>a + bi</CODE> and <CODE>c+di</CODE> is done according to formula:<P> <center><CODE>(a + bi) * (c+di) = (ac-bd) + (ad+bc)i.</center> In our case, {{{($a_real + $a_imag*i) * ($b_real + $b_imag*i) = ($a_real*$b_real - $a_imag*$b_imag) + ($a_real*$b_imag + $a_imag*$b_real)*i = $r_real + $r_imag*i}}}"; } elsif ( $operation eq '/' ) { my $d = $b_real*$b_real + $b_imag*$b_imag; $r_real = ($b_imag*$a_imag+$b_real*$a_real)/$d; $r_imag = ($b_real*$a_imag-$b_imag*$a_real)/$d; print " <B>Solution:</B>Division of two complex numbers <CODE>a + bi</CODE> and <CODE>c+di</CODE> is done according to formula:<P> {{{(a + bi) / (c+di) = (db+ca)/(c^2+d^2) + i*((cb-da)/(c^2+d^2))}}} <BR> In our case, {{{($a_real + $a_imag*i) / ($b_real + $b_imag*i) = $r_real + $r_imag*i}}}"; } ==section output r_real r_imag ==section check z=1 ==section practice perl $a_real = randint( -5, 5 ); $a_imag = randint( -5, 5 ); $b_real = randint( -5, 5 ); $b_imag = randint( -5, 5 );