Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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.
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
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
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 !
> 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
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
> 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
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.
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
So now remove the '=' at the end of your definition of r and see what happens.
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
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
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