Skip to main content
1-Visitor
March 16, 2016
Question

Plotting columns of a matrix

  • March 16, 2016
  • 5 replies
  • 19224 views

I have defined 2 range variables and an equation that uses these variables to create a matrix.

I would like to plot specific columns of this matrix against one of the range variables.

I have tried everything I can think of.  Running out of ideas.

I am a student trying to learn Mathcad.

Would appreciate any suggestions.  Thanks !

5 replies

23-Emerald IV
March 16, 2016

Example:

Success!
Luc

pshaw1-VisitorAuthor
1-Visitor
March 16, 2016

Luc,

Thank you so much for your reply.  I appreciate your help !

Below are my variables and my equation.  I would like to plot the first and last columns of the matrix L against the range variable d.

It seems like I'm doing something similar to your example (thanks for posting that !)

The error shown around L says . . . "These array elements must be scalars.  They cannot be vectors or matrices".

I'm confused . . . what am I doing wrong ?

Would appreciate any help.  Thanks again !

23-Emerald I
March 16, 2016

You can't have units in an index.

Look at this:

23-Emerald I
March 16, 2016

The subscript designation for a matrix element is row, column.  To plot the second column you would need the second subscript to be (ORIGIN+1).  To plot against range variable I, the subscript would be M[I,ORIGIN+1.

Luc's approach was a bit different; the superscript <ORIGIN> chooses a whole specific column of the matrix, then the single subscript specifies the row.  Same effect.

pshaw1-VisitorAuthor
1-Visitor
March 16, 2016

Thanks Fred, I appreciate your comments !

I'm trying to plot a whole column of the matrix L, specifically the first column, against the range variable d.

So I would like to plot a curve with the data points as :

Pt 1.  x = first value of the range variable d,  y = first value of the first column of matrix L

Pt 2.  x = second value of the range variable d,  y = second value of the first column of matrix L

.

.

etc

This doesn't seem like it would be this tough, but I'm struggling.

Would appreciate any help.  Thanks !

25-Diamond I
March 16, 2016

How about making d and D true vectors instead of just range variables and plot vector against vector.

Using the waterfall plot you may even plot every column in L against d at the same time

Werner

pshaw1-VisitorAuthor
1-Visitor
March 16, 2016

Hello Werner, thank you very much for your help and the file you posted !

If I evaluate the range variables "d" and "D", shouldn't this turn them into vectors ?

Unfortunately, after doing this I still have the same plotting problem.

Something curious I noticed . . . if I turn the range variables into vectors BEFORE the calculation for the matrix "L", the equation for "L" no longer works.

Does my equation for "L" depend on "d" and "D" being range variables and not vectors ?

I'm sorry my questions are so basic.  Please excuse my ignorance.

I'm very new to Mathcad, just trying to learn.

Thanks again for all your help !

25-Diamond I
March 16, 2016

Just spotted this reply of yours.

If I evaluate the range variables "d" and "D", shouldn't this turn them into vectors ?

Unfortunately - no. Its still a range even though it looks like a vector.

That's the problem and that's also the reason Fred an me had created d as a vector. Fred used the default setting for ORIGIN (0) which makes some expressions a little bit simpler.

As written in another answer there is an undocumented trick to quickly turn a range into a vector (d:=d=) but there also are more "official" ways and routines available to do so. The subject turns up ever so often here in the forum.

See my other answer elsewhere in this thread for a paper of Stuart describing the difference between vectors and ranges in more detail.

WE

25-Diamond I
March 16, 2016

Here is another approach. It looks like you are thinking "spreadsheet" but luckily you are using a math program now.

So you don't have to create a table just to get values or do a plot.

Use functions instead for better flexibilty:

Or you can show how L depends on D (that would mean plotting the rows of your table L against D)

And you may show the part of the 3D paraboloid which seems to be of interest

But unfortunately Primes 3D plot capabilities are mediocre up to unusable. Its not worth trying as editing the few things we can customize in a 3D plot is a real PITA.

Werner

pshaw1-VisitorAuthor
1-Visitor
March 16, 2016

Hello Werner,

I appreciate all your comments and the alternate way of doing things.

Unfortunately, the homework assignment I'm working on wants me to use range variables and generate a matrix of values.

I then need to plot certain columns of the matrix against one of the range variables.

Again, I appreciate all of your help, but I'm sort of constrained on the approach I can use to do this.

Thanks again, your support is greatly appreciated !

23-Emerald I
March 16, 2016
pshaw1-VisitorAuthor
1-Visitor
March 17, 2016

I thought I had something figured out.

I defined my two range variables and used the trick of immediately making them vectors for plotting purposes.

I used two separate indices to control the matrix generation.

The equation calculates all the correct numbers, but I was expecting a 9x9 matrix.

Why did this create an 81x1 vector instead of a 9x9 matrix ?

Sorry I'm not smart enough to figure this out.  Still trying to learn.

Would appreciate any help.  Thanks !

23-Emerald I
March 17, 2016

Didn't used to be able to do in-line evaluations.  Things aren't always the way they seem

pshaw1-VisitorAuthor
1-Visitor
March 17, 2016

Thank you Fred !

I feel so stupid that I didn't try that and realize it was actually a 9x9 matrix.

Thanks again, I really appreciate your help !