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
- Mute
- 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
- Mute
- 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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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 !

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Yeah great "undocumented trick" which destroys any attempts of succesfull debugging! LucMeekes I'm using Prime 3.1 but (not express). You can delete the comma after that you've wrote it. But perhaps that's also some undocumented trick.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted

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

02-09-2016
10:09 AM

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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.

Highlighted
##

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

02-09-2016
10:22 AM

02-09-2016
10:22 AM

Re: Variable Type "Generator" in Function

See above my remarks about the undocumented trick above.

See also that it won't work without inline eval:

There is a logic in the subject range vs vector, but I agree that its quite tricky.

You may be interested in some papers written by Stuart quite a while ago. They still apply to Prime in most parts. See attachments.

WE

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- 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

Highlighted
##

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

02-09-2016
11:01 AM

02-09-2016
11:01 AM

Re: Variable Type "Generator" in Function

Yes, correct. Its the inline eval, which does the job,

You could also define r:=1..2 and then v:=r=

r will be a range and v a vector.

WE