1x1 matrix addrow problem
|
05-31-2016, 09:44 AM
(This post was last modified: 05-31-2016 09:54 AM by std.)
Post: #1
|
|||
|
|||
1x1 matrix addrow problem
Hello,
As the title describes I have a problem with 1x1 matrices. I am writing down some calculation steps to use with my HP Prime for my exams. In the process, I calculate a matrix with dimensions nx1 (it is a column vector) and I want to add an element somewhere between the elements so that it becomes (n+1)x1. The "ADDROW" function works ok for matrices 2x1 or larger, but in the special case of 1x1 matrix (a.k.a. element matrix) it does not work and gives an error "Bad Argument Type". Example: I have a 3x1 matrix A=transpose([a1 a2 a3]) and I want to add a new element "anew" between a1 and a2 so that it becomes A=transpose([a1 anew a2 a3). ADDROW(A,[anew],2) works ok But if I have a 1x1 matrix A=(a1) and I want to add a new element "anew" either before a1 or after a1, so it becomes A=transpose([anew a1]) or A=transpose([a1 anew]) respectively, the ADDROW doesn't work. I could use "append", but it brings the new element to the end of the vector and the size of the vetror becomes 1x2 (row) not 2x1. I would like a general formula that would work in any case without having to alternate the calculations steps in order to handle the special case of 1x1. Any suggestions? Thanks |
|||
05-31-2016, 11:02 AM
(This post was last modified: 05-31-2016 11:04 AM by DrD.)
Post: #2
|
|||
|
|||
RE: 1x1 matrix addrow problem
(05-31-2016 09:44 AM)std Wrote: Example: I'm not real sure of your objective, but does this help? a1:=1; M0:=[a1]; // Original one element matrix transpose(prepend(M0,0)); // ==> transpose([0 a1]) transpose(append(M0,0)); //==> transpose([a1 0]) -Dale- -Dale- |
|||
05-31-2016, 11:52 AM
(This post was last modified: 05-31-2016 11:58 AM by std.)
Post: #3
|
|||
|
|||
RE: 1x1 matrix addrow problem
Thank you very much for your time.
Your solution works indeed. However, as I described on my initial post, I am writing down on paper the steps of a calculation workflow. My aim is to make a workflow as general as it can be, so that it can handle all the possible cases that I may come across at the exams (that includes both n=1 and n>1) without too much thinking. Plug and play! Really straightforward workflow without "if this" and "if that". Up to the point so far I have made the workflow to do the job with simple formulas, without using code to make a program (there is no need for programming it). Just really basic calculations on each step, but this last step buzzes me. What I want, is a single formula consisting of simple functions, that will work with whatever integer n (n=1 or n>1). I don't want to use "if" statements for the formulas, as it will make it vulnerable to typing mistakes by me. I don't want write down 2 formulas for this calculation step, one for each case (one formula for n=1 and one formula for n>1). I want one formula that will work for both cases if this is possible. I hope I described it better this time! |
|||
05-31-2016, 03:12 PM
(This post was last modified: 05-31-2016 03:13 PM by DrD.)
Post: #4
|
|||
|
|||
RE: 1x1 matrix addrow problem
(maybe?):
given: a1:=1; M0:=[0] CONCAT([a1],M0); // ==> [1,0] CONCAT(M0,[a1]); // ==> [0,1] Direct command line or programmable. -Dale- |
|||
06-01-2016, 05:04 PM
(This post was last modified: 06-01-2016 05:10 PM by std.)
Post: #5
|
|||
|
|||
RE: 1x1 matrix addrow problem
Thank you for trying to help me Dale. I really appreciate it.
I am aware of the Concat function but it behaves in this way: CONCAT([a1],anew) produces a row: [a1 anew] so I have to TRANSPOSE it in order to have a column CONCAT([column matrix nx1 goes here], anew) produces column, which does not need TRANSPOSE So I have to either use "if" statement (which I want to avoid as hell during the exams) or right down two cases for the calculation workflow which increases the complexity and I don't want it. It's not that I don't know how to uses "if" statements, neither that I cannot read a more complex flowchart. I am just trying to make a straightforward flowchart without branches (case1 n=1, case2 n>1 etc) so that other colleagues that don't have experience on algorithms can read and follow easily. An other problem is that concat always adds the new element at the end or at the start of the vector (depending how you apply it CONCAT(vector, anew) or CONCAT(anew, vector)). However it want to add the element anywhere between, which is possible only for n>1). |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)