[racket] Advice on using math/array and math/matrix to rewrite MATLAB code

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat May 3 10:29:12 EDT 2014

I forgot to add that there are a ton of (small) tests here:

https://github.com/plt/racket/blob/master/pkgs/math-pkgs/math-test/math/tests/matrix-tests.rkt


Also the step-vector function that produces a column vector looks like:

(require math/matrix)

(: step-col-vector : Real Real Real -> (Matrix Real))
(define (step-col-vector min max step)
  (for/matrix: (exact-ceiling (/ (- max min) step)) 1
               ([x (in-range min max step)])
               : Real
               x))

/Jens Axel




2014-05-03 8:43 GMT+02:00 Daniel Prager <daniel.a.prager at gmail.com>:
> I'm having a go at converting a pitch detection algorithm from MATLAB to
> Typed Racket, and which I'll Open Source if I can get it working, and am
> after a few pointers, since I'm new to TR and am finding it slow going.
>
> Examples of the kind of code I'm writing in my fledlging attempts:
>
> #lang typed/racket
>
> (define: (log2 [x : Real]) : Real
>   (define result (/ (log x) (log 2)))
>   (if (real? result)
>       result
>       0.0))
>
> (define: (build-step-vector [min : Real] [step : Real] [max : Real]) :
>   (Vectorof Real)
>   (for/vector: : (Vectorof Real)
>       #:length (ceiling (inexact->exact (/ (- max min) step)))
>       ([i (in-naturals)])
>     (+ min (* i step))))
>
>
> Suggestions of better idioms and choices most welcome! E.g. the second one
> could be written as a range -> array, multiplied by the step.
>
> Beyond that:
>
> Can anyone point me to examples of any code before/after converted from
> MATLAB (or Octave) to TR?
> What's a good scalar type to work with for floating point to start with?
> Which non-scalar type(s) should I favor: vectors, arrays or matrices?
> Any general tips to develop facility for this kind of stuff? I feel like I
> need to go "back to basics", but there seems to be a dearth of examples and
> tutorials. on math/... beyond the reference materials.
>
>
> Many thanks
>
> Dan
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
--
Jens Axel Søgaard


Posted on the users mailing list.