Skip to main content
1-Visitor
February 9, 2016
Solved

Variable Type "Generator" in Function

  • February 9, 2016
  • 2 replies
  • 5696 views

Hey guys,

I'm trying to build a function which multiplies a vector with each column of a matrix and returns this 'multiplied' matrix.

However I get some errors I don't understand.

Error.png

I have the feeling that mathcad fails to cope with this "generator-type" (e.g. 0..6) inside functions. However it could be a usage error

The sheet is attached below, does anyone see what is wrong with this or knows an easier way to solve the problem?

Best answer by LucMeekes

The error message isn't "Shitty", but righteous. There are several problems with your program. First you are defining M2 as a range, then in the for-loop you are using this M2 in an augment statement (that requires a vector or matrix as its argument) and assigning the result of the augment back to M2....

Is this what you are looking for?

Success!
Luc

2 replies

LucMeekes23-Emerald IVAnswer
23-Emerald IV
February 9, 2016

The error message isn't "Shitty", but righteous. There are several problems with your program. First you are defining M2 as a range, then in the for-loop you are using this M2 in an augment statement (that requires a vector or matrix as its argument) and assigning the result of the augment back to M2....

Is this what you are looking for?

Success!
Luc

sthomet1-VisitorAuthor
1-Visitor
February 9, 2016

Thanks for the answer, I knew there was an easier solution...

But please note that using a range (or "generator" because that's what I meant) as a vector is normally fine:

Error.png

So I stand by my statement that this error is Error.png!

25-Diamond I
February 9, 2016

> note that using a range (or "generator" because that's what I meant) as a vector is normally fine:

No, its not.

It may only look fine and ranges unfortunately look like vectors but they aren't. Ranges are iterators and should only be used for plotting, for-loops and indexing matrices (or vectors).

In your case you had used (without knowing, I guess) an undocumented trick: If you follow the range definition by a numeric evaluation (=), the range is converted to a vector.

So the r in your augment command is already a vector.

WE

25-Diamond I
February 9, 2016

However it could be a usage error

It is, as Luc already pointed out.

You wanted to create a dummy vector of the right size in the first line of your program but created a range variable. You can create that vector by simply assigning the last component any value.

You also had two errors (wrong indices) in your submatrix command.

Your routine works if you make the appropriate corrections

but nevertheless I would vote for Lucs appraoch.

WE

sthomet1-VisitorAuthor
1-Visitor
February 9, 2016

Error.png

The difference between vectors and ranges is not clear at all. It sometimes works and sometimes doesn't.

23-Emerald IV
February 9, 2016

So now remove the '=' at the end of your definition of r and see what happens.