Archive for the ‘Maths’ Category

The matrix calculator has been updated to include support for finding the inverse and determinants for square matrices of arbitrary dimensions.

http://zoofware.com/zoofware-matrix-machine/

I’ve been working on a little side project today which I’ve been thinking of doing for quite a while. It’s my intention to one day be able to write my own compiler for a custom designed language and so I have decided to start with something a little simpler: an algebraic equation evaluator.

I’ve also chosen F# to write it in, learning which has been on my to-do list for quite awhile now, so most of the last few hours has been spent mostly getting to grips with its syntax, a world away from C-style braces, and the functional way of doing things.

A basic parser is now working and the next step will be figuring out how to produce an expression tree, evaluate the nodes and return the result (either as a string or as some sort of expression object).

F# includes some neat stuff for this exact kind of situation, for example, a basic expression evaluator:

type expr =
    | Binary of string * expr * expr
    | Constant of float

let v = Binary("+", Constant 2.0, Binary("+", Constant(2.0), Constant(2.0)))

let rec eval v =
    match v with
    | Binary(op, lhs, rhs) ->
        match op with
        | "+" -> eval(lhs) + eval(rhs)
    | Constant(n) ->
        n       

(thanks to http://msdn.microsoft.com/en-us/magazine/cc164244.aspx#S6 for that ;) )

Essentially all that code does is define two types of expressions, one which consists of a binary operator with two operands (which are also expressions) and one that is simply a constant value.

The recursive evaluation function then iterates over the parent expression, its children and its children’s children etc. ad infinitum and evaluates them all. In theory every

expr

object will eventually evaluate down to a constant.

I whipped out Expression Blend today and gave the matrix calculator a bit of a tidy up. It now supports transposition and calculating the determinant of 2×2 matrices (and once I’ve figured out Leibniz’s or Laplace’s determinant formulae I’ll support arbitrary dimensions as well as finding the inverse).

http://zoofware.com/zoofware-matrix-machine/

Hi all, over the last two days I’ve developed a Silverlight matrix calculator which can add and multiply matrices of arbitrary sizes. I’m not 100% sure it has no bugs, so beware if you’re using it to cheat on your homework! :P

Zoofware Matrix Machine: http://zoofware.com/zoofware-matrix-machine/

It’s the only bit of coding I’ve done over the last few weeks :( However, I haven’t forgotten about the emulator. Once summer is upon us I’ll get cracking, but in the meantime I’m going to work on smaller maths related programs which don’t require as much time or effort to make and supplement my University course nicely. ;)