Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    simple matrix mathematics and using sylvester.js

    Hi - I'm very new to javascript coding (a new years resolution!) and I guess I'm jumping in the deep end with trying to code up some matrix operations using sylvester.js (sylvester.jcoglan.com/). However - I'm stuck at the first hurdle:

    I've got this in my head tag:

    Code:
    <script type="text/javascript" src="sylvester.js"></script>
    and then to start off small I thought I could define something and make sure I could get an output on the screen. For example, using function defined in the sylvester.js scripts.

    Code:
    <script type="text/javascript">
    
    var test = $M([
      [8,3,9],
      [2,0,7],
      [1,9,3]
    ]);
    
    </script>
    My (very) simple question is: I'd like now to display the matrix test on a webpage and this is where my limited knowledge is letting me down. A lot of the examples I've seen are using the matrices to transform an image etc. and then presenting a transformed image as output - but never the actual matrices.

    For background, the final program will take parameterised inputs from the user via a form, do all the fun matrix algebra in javascript and then outputs with be a text matrix of size m x n where m and n could be up to 100, and I'll probably so some plots. So I don't fancy putting each cell element individually into an array. I thought just trying to print results to the screen first would be a good step before I got too far...

    Any advice appreciated - even a link to an already available example is fine and I can chew through it myself.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    printing the Matrix itself will be bit of a hassle. the matrices are intended to only do/aid operations, after all.
    however what you would need to do is grab each element ($M.e(i, j)) for each index i and j where you can get the max value from $M.cols()/$M.rows(). and you will need a nested loop.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    meltedcheese (01-13-2012)

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply and the suggestion. I'll give it a shot and see how I go.

    I'm (attempting) to port a R statistical program into javascript - so hence the matrix being the main output.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •