A problem formatting a list returned from solve()

Messages in english

Modérateur : xcasadmin

niccolo
Messages : 22
Inscription : dim. mars 02, 2014 2:13 pm

A problem formatting a list returned from solve()

Message par niccolo » mar. juin 18, 2019 7:27 pm

I have a solution to some problem:

solution := [z-4, 25-2*z, z]

And I'm trying to see what happens when 'z' runs from 0 to 9, so I do:

makelist(x->subst(solution, [z=x]), 0, 9)

This works ok. 'xcas' displays the big list as a nice matrix which is easy to read.

The problem is that in reality my 'solution' is the result of solve(). When this happens, 'xcas' doesn't print the big list as a nice matrix.

Example:

solution := solve([x+y+z=21,2x+3y+4z=67],[x,y,z])
makelist(x->subst(solution, [z=x]), 0, 9)

xcas now prints the big list on one line, which is hard to read.

Why is that? Doesn't solve() return a real list?

niccolo
Messages : 22
Inscription : dim. mars 02, 2014 2:13 pm

Re: A problem formatting a list returned from solve()

Message par niccolo » mar. juin 18, 2019 10:44 pm

I've found the problem:

solve() returns a list of lists. So I have to use 'solution[0]', not 'solution'.

I wasn't aware of this because xcas displays this:

[[1,2,3]]

the same as this:

[1,2,3]

So I had no way of knowing there was a list inside :-(

That's a big problem.

Why does xcas do this?

niccolo
Messages : 22
Inscription : dim. mars 02, 2014 2:13 pm

Re: A problem formatting a list returned from solve()

Message par niccolo » mer. juin 19, 2019 12:33 am

Aaahhh.....

I think I understand why xcas displays [[1,2,3]] the way it does: it's a matrix. One that happens to have a single row.

Still, it's problematic that we can't tell the difference between [1,2,3] and [[1,2,3]].

Is there a hidden configuration option to "fix" this?

parisse
Messages : 5082
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: A problem formatting a list returned from solve()

Message par parisse » mer. juin 19, 2019 8:41 am

It's not displayed exactly the same, if you look closely, you will see that for a 1-line matrix the delimiters are a little bigger than for a list.

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: A problem formatting a list returned from solve()

Message par lukamar » jeu. juin 20, 2019 4:27 pm

Maybe the output would be more readable if the subtype of the result from solve was changed to _LIST__VECT?
That would, however, disable stacking the solutions one above another...

Répondre