OK, first let me say that you should always provide your Mathcad/Prime sheet (probably you will have to zip it before you can upload it here) rather than a pic as its hard to debug a picture and the willingness to help fades a little when one sees that its necessary to retype all from scratch rather than playing around with a provided worksheet.
In case of Prime you should additionally attach screenshots and/or pdf prints as because of the incompatibility of the file formats of the various versions and the inability of a higher version to save a file in the format of an older one, many people here can't read the format of the newer versions of Prime,, but maybe could help by just seeing a picture.
You don't say what kind of error message you get and its hard to see from the picture, but it looks to me like you had used the wrong type of index. In Mathcad we have two different types of indices. The literal index (keyboard: Ctrl+Shift+-) and the vector index (keyboard: [ ). You have to use the latter for indexing matrices and vectors like your array.
Using the right index you don't get an error anymore but sure not the result you expect as in the last line you use math[i and that way you just return a single scalar value and not the whole matrix (see the screenshot below)
Some remarks:
- Its not necessary to initialize the for-loop variable i to zero
- You don't have to provide the length of the array as function argument as Mathcad provides the function "last" to determine the last index of a vector
- You introduce two new arrays in your function, math and newArray. Thats inefficient and not necessary. Unless you have to reuse "older" array values for your calculations you can use the argument for the new values as well. This does not change anything in the array you provide as function argument. The function is playing with its own local copy. A program in Mathcad can't change any worksheet variable from within the program.
In my example function3 I set up a function which handles a scalar (in our case simply adding 1 to the argument) and then I call ths function with a vector as argument. As long as the calculations in that function don't make sense for vectors (like x^2 or sin(x), ...) Mathcad automatically performs so called "vectorization". This means that it feeds all elements of the argument vector one after the other into the function and collects and returns the results in a vector. If you want to be on the safe side you apply vectorization manually (the arrow above the expression).
Give it a try yourself - define f(x):=x*x (don't type x^2) and call that function with a vector as argument. Without vectorization you will get a scalar (the dot product), with vectorization you get a vector with squared elements as result.
