Padding a vector using Insert[ ]?

Hello,
I am looking for some help with the INSERT command in Mathematica.
I have a 4 x1 column vector

In which i have inserted 4 additional rows of zeros at the top, thus making it a (8 x 1) column vector.

2.png

If you notice that the original terms that now occupy the 5h, 6th, 7th & 8th values, are now enclosed in braces { }.

So it seems that the new 8 x 1 column vector is cannot be multiplied with a 8 x 8 matrix, which I was trying to do and resulted in this error.

I get this message

4.png

Would you know what the issue is with the INSERT command in my case?

Thanks

Aslam,

You should normally post your code using the third button on the formatting bar. Without seeing an example that reproduces your problem, it is harder to answer.

Also, You should never name anything beginning with capital letters because you might interfere with the internal workings of Mathematica.

it appears to me that you are not creating a vector in NDisp but a matrix:

vector = {1,2,3,4}
matrix = Transpose[{{1,2,3,4}}]

which is the same as

matrix = {{1},{2},{3},{4}}

To add elements, normally I use Join (although Insert works)

dv = Join[{0, 0, 0}, nd]

or

dv = Join[ConstantArray[0, 3], nd]

To fix your issue, you can convert your matrix to a vector:

Flatten[matrix]

or you can convert your inserted vector to a matrix

Join[Transpose[{{0, 0, 0}}, nd] 

or

Join[Transpose[{ConstantArray[0, 3]}], nd]

You can see if the structure of what you create is consistent by doing a

dv //FullForm 

to see the internal representation of your expression.

Regards

Neil

Hi Neil.
Thanks very much for your reply.
I did try the ‘Flatten’ first and then tried the ‘Join’ command, neither of them worked in my case.
I can seem to understand, why the LinearSolve command creates a matrix when its supposed to be a vector.

I have attached the code, and would greatly appreciate your help.

Regards,

Q1_OP_uTube turtorial aoproach_CP_.nb (316 KB)

It is best to provide minimal examples of the problem at hand. The example notebook is far from minimal.

The Print statements indicate there is a problem here.
DisplVector = Insert[NDisp, 0, {{1}, {1}, {1}, {1}}];

It places zeros, rather than the list {0}, inside a matrix. Which makes it no longer a matrix. Neil Singer already explained this issue so I won’t repeat that.

Hi Daniel.
Thanks for clarifying it further.

My code is fixed and works now!

Very much appreciated.

-Aslam

Thanks again.
My code is fixed and works now!

Very much appreciated.

-Aslam