HP Forums

Full Version: Exact items for a matrix from a program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi all,
there is a way to get exact results for the items of a matrix, from a Home program (non CAS program)?
For example, in my last program, if a matrix is returned it has [[1, 0.5], [0.5, 0.25]]and I would like to return also in CAS view [[1, 1/2], [1/1, ¼]] without hitting "a b/c".
Something like the nice QPI (and QPImat) program by Han (inside the program)...

I tried to use exact() but no luck for now...

Thank you
Salvo
(06-07-2015 08:07 PM)salvomic Wrote: [ -> ]hi all,
there is a way to get exact results for the items of a matrix, from a Home program (non CAS program)?
For example, in my last program, if a matrix is returned it has [[1, 0.5], [0.5, 0.25]]and I would like to return also in CAS view [[1, 1/2], [1/1, ¼]] without hitting "a b/c".
Something like the nice QPI (and QPImat) program by Han (inside the program)...

I tried to use exact() but no luck for now...

Thank you
Salvo

This isn't exactly what you seek, but the STRING function has an option to convert decimals into fractions. For example:

STRING([[.1,.2],[.3,.4]],8) --> "[[1/10,1/5],[3/10,2/5]]"

The output is ugly, not "Textbook" style, but at least the fractions are there. If you want to present the result in a pretty fashion, you'd have to loop through the matrix and STRING each entry separately, I suppose.
(06-08-2015 06:56 AM)Joe Horn Wrote: [ -> ]This isn't exactly what you seek, but the STRING function has an option to convert decimals into fractions. For example:

STRING([[.1,.2],[.3,.4]],8) --> "[[1/10,1/5],[3/10,2/5]]"

The output is ugly, not "Textbook" style, but at least the fractions are there. If you want to present the result in a pretty fashion, you'd have to loop through the matrix and STRING each entry separately, I suppose.

thank you Joe, this works, but I want to export numbers to be treated after the calculation...
For example, ref() gives exact result, but exported from inside my program it doesn't export fractions but reals... (also using exact() command)...

Salvo
Then I'd suggest using a loop that scans through the entire matrix (e.g. R goes from 1 to rowDim(M1), and C goes from 1 to colDim(M1)), and outputs exact(row(col(M1,C),R) at each iteration. Or something like that. Not a single command, but it works.
(06-10-2015 05:50 AM)Joe Horn Wrote: [ -> ]Then I'd suggest using a loop that scans through the entire matrix (e.g. R goes from 1 to rowDim(M1), and C goes from 1 to colDim(M1)), and outputs exact(row(col(M1,C),R) at each iteration. Or something like that. Not a single command, but it works.

thank you, I'll try it
Reference URL's