cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Calculation of the mean in an Array

DG_8871348
4-Participant

Calculation of the mean in an Array

Hi,

I have a simple Problem however I'm searching since nearly one hour for the solution. 

I'm looking to calculate the mean in an Array. I Have R=(x1, x2, ....) and i want to calculate the mean of every value in the Array like Rm1=(x1+x2)/2 Rm2=(x2+x3)/2 ... and so on. 
How does it work im Mathcad? The normal Matrix Indicies with i and i+1 doesn't work.

I also attached a short Version of the Mathcad file, especially to focus on this Problem. Thanks for helping 😊

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:DG_8871348)

Here is your own approach using a range variable, but as the last element of the vector has no successor, the range to use must run only up to Anz.i-1 and so you can't use i, you need a new range variable - k in my example (but of course you also could redefine i for that purpose).

Werner_E_0-1623109570282.png

 

Nonetheless I would prefer defining a small utility function

Werner_E_1-1623110010341.png

 


But is there any shorter and easier Solution for this Problem without Programming? 

Luc's "Mean2" function IS quite short (and can be written even a little bit shorter if you assume ORIGIN=0) does NOT use programming (so it could be used in the free Express version of Prime, too).

 

The built-in function "movavg" suggested by Luc makes the same calculations but always returns a vector of the same length by prepending first vector element.

Werner_E_2-1623110134820.png

To get rid of it you may use the "submatrix" command

Werner_E_3-1623110198205.png

(assuming ORIGIN=0 as is the case in your sheet).

 

 

 

View solution in original post

5 REPLIES 5
LucMeekes
23-Emerald III
(To:DG_8871348)

You do realise that the result of this operation produces an array that has one less elements...?

This is one way to do it:

LucMeekes_0-1623087614384.png

The result for your array is:

LucMeekes_1-1623087632025.png

There's also a built-in function for it: Moving average. Try:

movavg(Ri,2)

 

Success!
Luc

DG_8871348
4-Participant
(To:LucMeekes)

Thanks for the fast Reply.
But is there any shorter and easier Solution for this Problem without Programming? 

LucMeekes
23-Emerald III
(To:DG_8871348)

Look again to my post: movavg is built in.

 

Success!

Luc

Werner_E
25-Diamond I
(To:DG_8871348)

Here is your own approach using a range variable, but as the last element of the vector has no successor, the range to use must run only up to Anz.i-1 and so you can't use i, you need a new range variable - k in my example (but of course you also could redefine i for that purpose).

Werner_E_0-1623109570282.png

 

Nonetheless I would prefer defining a small utility function

Werner_E_1-1623110010341.png

 


But is there any shorter and easier Solution for this Problem without Programming? 

Luc's "Mean2" function IS quite short (and can be written even a little bit shorter if you assume ORIGIN=0) does NOT use programming (so it could be used in the free Express version of Prime, too).

 

The built-in function "movavg" suggested by Luc makes the same calculations but always returns a vector of the same length by prepending first vector element.

Werner_E_2-1623110134820.png

To get rid of it you may use the "submatrix" command

Werner_E_3-1623110198205.png

(assuming ORIGIN=0 as is the case in your sheet).

 

 

 

DG_8871348
4-Participant
(To:Werner_E)

Thanks, the first Example was the Perfect Solution 😎

Announcements

Top Tags