Arc Forumnew | comments | leaders | submit | wgac's commentslogin

I found some errors in the recent post. Here is the (I hope so) final version or rez and imz. Enjoy :)

    ;;Realis of complex number z
    (def rez (z)
         (with (lz (tocons z) i 0 j 0)
         (until (or (is i (len lz))
                    (and (isnt (lz j) #\e)
                         (or (is (lz i) #\+)
                             (is (lz i) #\-)))) 
            (if (is i 0) (++ i) (do (++ i) (++ j))))
            (toint (firstn i lz))))

    ;;Imaginaris of complex number z
    (def imz (z)
         (with (lz (tocons z) i 0 j 0)
         (until (or (is i (len lz))
         	    	(and (isnt (lz j) #\e)
	    	     (or (is (lz i) #\+)
	    	     	 (is (lz i) #\-)))) 
    	(if (is i 0) (++ i) (do (++ i) (++ j))))
    	(toint (if (pos #\i lz) (rem #\i (nthcdr i lz)) 0))))

-----


Ok. So I've looked at the rez and imz and found the solution to the problem with scientific notation. Here are my results:

    ;;Realis of complex number z
    (def rez (z)
      (with (lz (tocons z) i 0 j 0)
      (until (and (isnt (lz j) #\e) (or (is (lz i) #\+) (is (lz i) #\-))) 
           	  (if (is i 0) (++ i) (do (++ i) (++ j))))
      (toint (firstn i lz))))

    ;;Imaginaris of complex number z
    (def imz (z)
      (with (lz (tocons z) i 0 j 0)
      (until (and (isnt (lz j) #\e) (or (is (lz i) #\+) (is (lz i) #\-))) 
           	  (if (is i 0) (++ i) (do (++ i) (++ j))))    
      (toint (if (pos #\i lz) (rem #\i (nthcdr i lz)) 0))))
I've also written zbar which returns complex conjugate of a number:

    ;;Complex conjugate of number z.
    (def zbar (z)
         (toint (join (tocons (rez z)) 
         	      (if (> (imz z) 0) '(#\-) '(#\+)) 
		      (tocons (abs (imz z))) 
		      '(#\i))))
And once more thank you, conanite.

-----


Thanks for the feedback, conanite :) I think I know how to cope with that problem. I'll post my results as soon as I have some spare time. I'm also planning to successively add more elaborate mathematical functions. Maybe some numerical integration or solving differential equations.

-----


Here are definitions of the basic trigonometric functions alternative to the Taylor series. They use complex numbers and Euler's formula. By the way, could someone tell me how to make my code stand out in a comment? Thanks.

(= e 2.71828182845904523539)

(= pi 3.14159265358979323846)

(def sin (x) (/ (- (expt e (* 0+1.i x)) (expt e (* 0-1.i x))) 0+2i))

(def cos (x) (/ (+ (expt e (* 0+1.i x)) (expt e (* 0-1.i x))) 2.0))

(def tan (x) (/ (sin x) (cos x)))

(def cot (x) (/ (cos x) (sin x)))

-----

1 point by thaddeus 5540 days ago | link

I'm assuming when you say 'standout' you mean format/indent your line breaks for code.... for that you add 4 spaces before each line of code. If you mean standout = bold, no clue. T.

-----

1 point by wgac 5540 days ago | link

Thanks.

-----