Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Apr 07, 2022
12:22 PM

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

Apr 07, 2022
12:22 PM

Manipulate Size of Arrays

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.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Apr 07, 2022
01:30 PM

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

Apr 07, 2022
01:30 PM

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

7 REPLIES 7

Apr 07, 2022
01:21 PM

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

Apr 07, 2022
01:21 PM

@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

Apr 07, 2022
01:30 PM

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

Apr 07, 2022
01:30 PM

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

Apr 07, 2022
02:04 PM

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

Apr 07, 2022
02:04 PM

@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 🤕)

Apr 08, 2022
07:09 AM

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

Apr 08, 2022
07:09 AM

submatrix works wonderful, thank you very much.

Also thanks to all other solutions.

👍

Apr 07, 2022
01:44 PM

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

Apr 07, 2022
01:44 PM

@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

Apr 07, 2022
02:58 PM

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

Apr 07, 2022
02:58 PM

Here is an approach which catches all divisons by zero. By filterNaN of course you lose the information about which row throws an error.

Apr 07, 2022
03:53 PM

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

Apr 07, 2022
03:53 PM

@Werner_E wrote:

Stuart