Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hello,
I'm using MathCad Prime 2.0 and am pretty new to the software but am having trouble passing variables as arguments to functions.
I am trying to use a For loop within my function and don't think I am doing anything wrong in terms of syntax because even if I just copy the For loop example in the tutorial I don't get the answer shown in the tutorial. I have attached a screenshot of the problem but it's also typed below if that helps.
In other words, the result I get is as though the 'vec' array has not be read. The answer I would expect would be a column vector containing 4 items, all zeros except the fourth, which would be a 7. Has anyone else had this problem? I can't work out what I'm doing wrong.
On a similar example the variables I am trying to assign as arguments to a function result in the error message 'The variable is undefined. Check that the label is set correctly'. I'm pretty sure that this is because the arguments are not passing to the function rather than a labelling problem.
Any help would be hugely appreciated!
Thanks!
Firstly you don't need to define vec above the function and you should evaluate f(vec) below.
Mike
Thanks Mike - I've managed to get this working now. I now have one more question which hopefully you won't mind answering!
I have two column vectors and I would like to find the minimum for each row (i.e. minimum of row 1 for vector 1 and 2, then min of row 2 of both vectors etc), writing the values to a new column vector. It seems like a simple thing to do but I can't work out a way to do this other than shown below. However, it doesn't seem to be working as my function seems to only return the overall minimu of the matrix rather than the minimum of each row. I hope this is making sense!
Whereas the answer I am looking for is Test(B)=[1, 1, 4, 7, 5, 2] (as a column vector)
I can't see what I am doing wrong! I was unable to convert your worksheet, if you have an example would you mind attaching a screenshot?
Thanks!
Like below?
Mike
Perfect, thanks Mike!
No problem at all.
Mike
I hope you don't mind but I have another question. I am using a solve block to maximise a variable (j), but it isn't working. I can't tell where the problem lies. Do you have any ideas?
Any help would be hugely appreciated - thanks!
How about this?
Mike
Amazing, thanks again!!
Here's a possible alternative approach ...
(given that Prime has an array row operator, the trick of transposing and passing to a 'columnized' function shouldn't be necessary - just modify ColReduce and ColApply to use the row operator)
Stuart
As Stuart indicates, Mathcad Prime does have an array operator and i just got my Prime working
Mike
Example in M15 attached Sorry I haven't got Prime at the moment, so you will have to convert it.
Mike