Using Satimage's Smile Numerics OSAX

Hello to any users of the Numerics.osax. I’m working my way through the math functions. Looking at this series of linear equations:

2w + 4v + 6z = 2
3w + 3v + 7z = 3
6w - 2v + 8z = 5

I’d expect an answer that looks like {-1.5,-1.0,1.5} in a column per MS Excel. I use this Applescript:


set n to 3
set m to {2, 4, 6, 3, 3, 7, 6, -2, 8}
set A to {class:matrix, nrows:n, ncols:n, array of real:m}
set b to {class:matrix, nrows:n, ncols:1, array of real:{2, 3, 5}}
return solve linear system A RHS (array of real of b)

I get this back:
«data Lido4E6F742061207265636F726462756F64000000000000F8BFFEFFFFFFFFFFEFBF000000000000F83F»

Which, as AEPrint, is this:
‘Lido’(‘utf8’("-1.5
-0.9999999999999998
1.5
"))

Almost close enough, but what is Lido data?

If I change the Applescript to this mathematical equivalent:


set n to 3
set m to {2, 4, 6, 3, 3, 7, 6, -2, 8}
set A to {class:matrix, nrows:n, ncols:n, array of real:m}
set b to {class:matrix, nrows:n, ncols:1, array of real:{2, 3, 5}}
set Inverse_A to invertmatrix A
return multmatrix Inverse_A with b

I get this back:
nrows: 3
ncols:1
array of real:«data Lido4E6F742061207265636F726462756F64100000000000F8BFF8FFFFFFFFFFEFBF040000000000F83F»

Which in AEPrint is
{ ‘ncol’:1, ‘nrow’:3, ‘Lido’:‘Lido’(‘utf8’("-1.500000000000004
-0.9999999999999991
1.500000000000001
")) }

Not as close. You can find the differences in the Lido string.

What’s going on? Do I have to worry about the user-unfriendly Lido data? Late Night Software gives a AEPrint command, but I don’t like that I should need it. There is a LIDO acronym: Lightweight Information Describing Objects. Is that it?

At the moment, not enthused with the osax.

…Mick (Happy New Year to all)

array of real
array of real (type), pl arrays of real a packed list of real. Can be coerced to an AppleScript list with “as list of real” or “as list of integer”. Conversely, a list of real may be translated using “as array of real” for fast computation. (defined in Satimage.osax)

return (solve linear system A RHS (array of real of b)) as list of real

Hello -

Thank you. Works for the linear solution, but not the matrix multiplication.


return (multmatrix Inverse_A with b) as list of real

Throws an error.


return (multmatrix Inverse_A with b) as array of real

returns

[ ‘Lido’(‘utf8’("-1.500000000000004
-0.9999999999999991
1.500000000000001
")) ]

Same as above.

…Mick

Hello.

Can’t you just iterate of the rows of the matrix, and pull out each as a list of real?

Hi -

I could, and I have :slight_smile: but I can’t think that’s the polished approach.

…Mick

Well, if it doesn’t come with enough polish (the OSAX) then I suggest you roll your own matrix to list of list handler.

Lapack shold be close by with Asoc.

Edit

If you really want to stay native, nobody is hindering you in writing your own Gauss-Jordan inverted matrix algorithm, or converting an implementation to AppleScript. :slight_smile:

(item 1 of the result) as list of real

McUsr - I actually tried that. :slight_smile: Got about 20% into it, discovered my C is beyond rusty (last seen about '96), and found that the Numerics.osax has Lapack results, matrix multiplication, and matrix inversion. All I should need. However, as always with Applescript, the problems are in the syntax. :frowning: See below. Thanks.

MM - Thank you, but still a problem. Here’s my code:


set n to 3
set m to {2, 4, 6, 3, 3, 7, 6, -2, 8}
set A to {class:matrix, nrows:n, ncols:n, array of real:m}
set b to {class:matrix, nrows:n, ncols:1, array of real:{2, 3, 5}}
set Inverse_A to invertmatrix A
set theResult to (multmatrix Inverse_A with b)
return (item 1 of theResult) as list of real

It throws this error: Can’t make item 1 of {class:matrix, ncols:1, nrows:3, array of real:«data Lido4E6F742061207265636F726462756F64100000000000F8BFF8FFFFFFFFFFEFBF040000000000F83F»} into type list of real.

I can see in Script Debugger that item 1 is the Lido data. So, still confused, since math-wise, Inverse_A*b is the same as the linear solution. Glad a Numerics user is here. My French is worse than my C. :slight_smile:

…Mick

Hello…
I don’t use Numerics.Osax at the present time. But what does just the result as list of real yield?

To me it looks like you are trying to take 1 item of the result, (which may be an item), and coerce that to a list of real.

Try to see what you get without any coercions, then coerce to a list of real, then try to pick out values.

That is the way I would have done it, and good luck! :slight_smile:

I’m pretty sure there are some AppleScript Examples out there, if you are in luck with your googling.

set n to 3
set m to {2, 4, 6, 3, 3, 7, 6, -2, 8}
set A to {class:matrix, nrows:n, ncols:n, array of real:m}
set b to {class:matrix, nrows:n, ncols:1, array of real:{2, 3, 5}}
set Inverse_A to invertmatrix A
set theResult to (multmatrix Inverse_A with b)

class of theResult
theResult

return (array of real of theResult) as list of real

:slight_smile:

edit: there is no item 1 of {class:matrix, ncols:1, nrows:3, array of real:«data Lido4E6F742061207265636F726462756F64100000000000F8BFF8FFFFFFFFFFEFBF040000000000F83F»}, it’s a record!

Hi MM -

Got it. Thank you. Your “it’s a record!” maybe should be “it’s not a record!”? :slight_smile:

McUsr – mostly I search here :slight_smile: Thanks for chiming in.

…Mick

MM - Oh, wait, I really do get it now. The class was “matrix” – treat it like a record!

Thanks.

…Mick