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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

23-Emerald I

## building a histogram

1. One of the features from Mathcad 15 that I miss (occasionally) is the ability to display a histogram of a vector of data--the ability to display the general shape of a distributed variable is valuable.

Prime (at least Express, where I'm stuck) doesn't have that feature.  Being bored to tears with the pandemic, I set out this morning the be able to take a vector of data (of random length) and develop a histogram of that data.  (A histogram, for those not familiar, divides a range of values into a set of discrete "bins" and returns the count of values in each bin.)

I was partially successful.  The attached Prime 4.0 file demonstrates the technique.  It also demonstrates several issues that I'm hoping someone smarter than I can help me with.

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald III
(To:Fred_Kohlhepp)

Fred,

The Prime express file with additional functions contains the histogram function. I remember working on that to make it work.

Success!
Luc

9 REPLIES 9
24-Ruby V
(To:Fred_Kohlhepp)

Would this help:

23-Emerald I
(To:Werner_E)

That looks like a great fix!

but nn and rows(M) are both simply a count.  If we have a vector of measurements with units, then dn has those units too . . .

Still works, but how do we justify the units in the graph?

24-Ruby V
(To:Fred_Kohlhepp)

Its the necessary unit to get an area of (unitless) 1 under the curve.

You get the same unit when you use pnorm with units, too.

23-Emerald I
(To:Fred_Kohlhepp)

Doesn't pay to argue with Werner!

My rough tool works and makes sense, but it doesn't compare with Luc's effort!

23-Emerald III
(To:Fred_Kohlhepp)

Fred,

The Prime express file with additional functions contains the histogram function. I remember working on that to make it work.

Success!
Luc

23-Emerald I
(To:LucMeekes)

Luc,

WOW!!

One small addendum:  there are expressions to assist in defining how many bins you should have, seem to help.

23-Emerald III
(To:Fred_Kohlhepp)

Hi Fred,

You're right, but choosing the optimum number of bins is outside of the scope of the histogram function. I tried to mimic the functionality of the Premium function.

And I see now there's work to be done. Prime's built in histogram function accepts units (according to the help). Mine doesn't ☹️ unless the first argument is an array with the intervals specified, and also has a unit attached (the same unit as the second argument).

Regards,

Luc

23-Emerald I
(To:LucMeekes)

You're right, but choosing the optimum number of bins is outside of the scope of the histogram function. I tried to mimic the functionality of the Premium function.

True, but my simple tool fails if it trips over a bin with no values inside.  And, surprisingly, you don't need a huge number of bins to get a good representation.

And I see now there's work to be done. Prime's built in histogram function accepts units (according to the help). Mine doesn't  unless the first argument is an array with the intervals specified, and also has a unit attached (the same unit as the second argument).

I suspect that the "UnitsOf" function would be very useful here, used as I have to strip units from differential equations for solving, then restoring them.

Attached one final iteration on a simple effort.

23-Emerald III
(To:Fred_Kohlhepp)

Yep, I need to use UnitsOf(), not to strip off, but to add units.

The updated file is attached to the other thread.

Luc

Announcements
Top Tags