Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.5K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Padding a vector using Insert[ ]?

POSTED BY: Aslam Kittur
5 Replies

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.

POSTED BY: Daniel Lichtblau

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

POSTED BY: Neil Singer

Thanks again. My code is fixed and works now!

Very much appreciated.

-Aslam

POSTED BY: Aslam Kittur

Hi Daniel. Thanks for clarifying it further.

My code is fixed and works now!

Very much appreciated.

-Aslam

POSTED BY: Aslam Kittur

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,

Attachments:
POSTED BY: Aslam Kittur
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard