Hello,
let´s say I have two arrays with the same length.
Also I have a function which wants to do further calculations with the arrays.
I need some kind of trick where I can ignore the first element of A and B.
I tried a for-loop from k = 1 to length(B) but no... doesnt work this way.
I expect a result array like this with 5-1 = 4 elements (first row deleted).
In best case I need all the array manipulations within the function C.
Thanks
Solved! Go to Solution.
Here's a function C that does what you want, for input vectors of any length >1, with two examples of usage:
And it also works in Prime express...
Success!
Luc
@xyz123 wrote:
Hello,
let´s say I have two arrays with the same length.
Also I have a function which wants to do further calculations with the arrays.
I need some kind of trick where I can ignore the first element of A and B.
I tried a for-loop from k = 1 to length(B) but no... doesnt work this way.
I expect a result array like this with 5-1 = 4 elements (first row deleted).
In best case I need all the array manipulations within the function C.
Thanks
Would something like this suffice? ...
It should give the result of dividing the vectors, up to the shortest of the two and excluding the first element. It doesn't check for a single-element vector.
Stuart
Here's a function C that does what you want, for input vectors of any length >1, with two examples of usage:
And it also works in Prime express...
Success!
Luc
@LucMeekes wrote:
Here's a function C that does what you want, for input vectors of any length >1, with two examples of usage:
And for those who prefer to stick to ORIGIN = 0, here are a couple of handy Mathcad Express functions that I keep in my default worksheet and that simplify calculations like this.
Stuart
(subvector is easily made ORIGIN-independent, but I confess that it hurts my eyes to look at it and all those shouty capitals give me a headache 🤕)
submatrix works wonderful, thank you very much.
Also thanks to all other solutions.
👍
@xyz123 wrote:
Hello,
let´s say I have two arrays with the same length.
Also I have a function which wants to do further calculations with the arrays.
I need some kind of trick where I can ignore the first element of A and B.
I tried a for-loop from k = 1 to length(B) but no... doesnt work this way.
I expect a result array like this with 5-1 = 4 elements (first row deleted).
Just some added comments:
1. (Most important) Please attach a copy of the worksheet with the issue.
a. There are several potential causes of Mathcad errors that are either difficult or impossible to see from just an image (for example, what ORIGIN is set - that's why I made my function ORIGIN-independent).
b. It's generally not possible to read the error messages, and hence significant clues may be missing.
2. There's no need to predefine a for-loop variable.
3. The Mathcad function length returns a single number. The for loop will just assign 5 to k.
Points 1 and 3 are demonstrated below:
The error in your program appears to be due to you having ORIGIN = 0, which means the maximum index is 4. Consequently, k tries to index a non-existent element and Mathcad raises an appropriate error ... which you can't read the details of but would have been visible to the reader in the worksheet.
4. A Mathcad program returns the value of the last expression it calculated; in this case, just a[k/b[k. If you want to return a vector, you need to assign the result of each operation to a variable. You also need to take care that you use indices correctly. In your example, you need to make the indices for a and b one greater than the return vector index. Here's a slightly simplified version of the C function that assumes ORIGIN = 0 that takes into account the above:
Hope that helps.
Stuart
Here is an approach which catches all divisons by zero. By filterNaN of course you lose the information about which row throws an error.
@Werner_E wrote:
Here is an approach which catches all divisons by zero. By filterNaN of course you lose the information about which row throws an error.
Stuart