Extracting values from vectors/matrices in home
|
02-24-2016, 10:15 AM
Post: #1
|
|||
|
|||
Extracting values from vectors/matrices in home
Hello !
How can I extract a specific value from a vector or a matrix in home? In cas I can extract the 2 value of a vector simply with [2 4 6](2) and I get 4. If I do the same in home I get [4 8 12], so [2 4 6](2) will be interpreted as [2 4 6]*(2) Is there a way to do this in home without having to store the vector in a variable? Typical use is when you solve a polynomial equation with proot() or a linear system with RREF() and want to extract the single solutions. Thank you very much for the help Reto |
|||
02-24-2016, 12:34 PM
Post: #2
|
|||
|
|||
RE: Extracting values from vectors/matrices in home
Reserved variables are great for this kind of thing, but you said you don't want to use variables, so how about this, in HOME:
col([2,4,6],2); // ==> [4] -Dale- |
|||
02-24-2016, 01:05 PM
Post: #3
|
|||
|
|||
RE: Extracting values from vectors/matrices in home
CAS("[2 4 6](2)") will work in HOME and return 4 but I'm afraid it's not what you're looking for. Using a dedicated variable may be simpler.
|
|||
02-24-2016, 04:06 PM
(This post was last modified: 02-24-2016 04:07 PM by Han.)
Post: #4
|
|||
|
|||
RE: Extracting values from vectors/matrices in home
Just save your vector or matrix into ad global variable. For example:
M1:=proot( [1,5,6] ); // now M1 contains the vector [-3 -2] M1[1] returns -3 and M1[2] returns -2 For matrices, use M1[m,n] to extract the element in row m and column n. You can optionally use the following syntax: M1(1) and M1(2), or M1(m,n) for a matrix but I do not recommend this syntax because (esp. in CAS programs) it is not clear if something like: myvar(m,n) should be interpreted as a 2-variable function myvar with inputs m and n, or as the m,n entry of a matrix named myvar. I know you specified not using variables, but global variables exist whether you use them or not, so I say go ahead and use them. Graph 3D | QPI | SolveSys |
|||
02-25-2016, 08:05 AM
Post: #5
|
|||
|
|||
RE: Extracting values from vectors/matrices in home
(02-24-2016 04:06 PM)Han Wrote: Just save your vector or matrix into ad global variable. For example: I use global variables for values I want to save for future use, and there are only 10 already defined global variables for matrices, I know I could try to always let one of them unused so that I can use it for this scope, but then they will be 9... Storing a vector/matrix in a variable always implies more steps. So the way proposed by Dale is probably the best one, as I can assign "col()" to a user key. It would be nice to use col(ans,2), but it looks like "col" uses the Cas Ans and not the home one. Same thing with CAS("Ans(2)"), this is quite logical as I am using CAS() Is there a way to use col() in RPN mode? |
|||
02-25-2016, 08:27 AM
Post: #6
|
|||
|
|||
RE: Extracting values from vectors/matrices in home | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)