Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Variable Type "Generator" in Function

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
05:39 AM

02-09-2016
05:39 AM

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.

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?

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
07:43 AM

02-09-2016
07:43 AM

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

12 REPLIES 12

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
07:43 AM

02-09-2016
07:43 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
09:13 AM

02-09-2016
09:13 AM

Re: Variable Type "Generator" in Function

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:

So I stand by my statement that this error is !

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
09:50 AM

02-09-2016
09:50 AM

Re: Variable Type "Generator" in Function

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
09:58 AM

02-09-2016
09:58 AM

Re: Variable Type "Generator" in Function

> 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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
09:59 AM

02-09-2016
09:59 AM

Re: Variable Type "Generator" in Function

What version of Prime are you using.

In Prime 3.1 (express) I can enter the range only as:

(So NOT without the comma), and yes, then it behaves as a vector as is shown by the subsequent evaluations and by:

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
10:09 AM

02-09-2016
10:09 AM

Re: Variable Type "Generator" in Function

> I can enter the range only as:

No you can. Simply type r:1..2

instead of the semicolon ";" we are used to from older versions, you have to type two ellipses ".."

> then it behaves as a vector

in fact it IS a true vector because of the inline evaluation after the defintion (undocumented trick).

And because we cannot make inline evaluation from within a program the trick can't work with ranges inside of programs.

WE

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
10:09 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
10:13 AM

02-09-2016
10:13 AM

Re: Variable Type "Generator" in Function

Hm. In Prime 3.1 it seems they've done something about ranges. I checked the following to test for 'vectorness', can you find more tests?

Note that it all started with the definition r:1,2;2= (gives "r:=1,2..2=[1 above 2]").

Ah. I found it. it works as long as the '=' is at the end of the definition (of r) If I remove the '=', so my definition becomes:

r:1,2;2 (gives "r:=1,2..2") then the vector operations do NOT work anymore.

And the evaluation (the '=') you cannot do inside a program, that's why it can never work what Stefan tried.

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-09-2016
10:14 AM

02-09-2016
10:14 AM

Re: Variable Type "Generator" in Function

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

Top Tags