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

building a histogram

SOLVED
Fred_Kohlhepp
Sapphire III

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

Re: building a histogram

Fred,

 

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

Check https://community.ptc.com/t5/PTC-Mathcad/Prime-Express-A-joke/m-p/604216.

For your example:

LucMeekes_0-1606234979544.png

 

Success!
Luc

View solution in original post

9 REPLIES 9

Re: building a histogram

Would this help:

Werner_E_0-1606230254871.png

 

Re: building a histogram

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 . . .

Fred_Kohlhepp_0-1606233023064.png

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

Re: building a histogram

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.

Werner_E_0-1606246704873.png

 

Re: building a histogram

Doesn't pay to argue with Werner!

Fred_Kohlhepp_1-1606333784121.png

Fred_Kohlhepp_0-1606333729369.png

 

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

 

Re: building a histogram

Fred,

 

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

Check https://community.ptc.com/t5/PTC-Mathcad/Prime-Express-A-joke/m-p/604216.

For your example:

LucMeekes_0-1606234979544.png

 

Success!
Luc

View solution in original post

Re: building a histogram

Luc,

 

WOW!!

 

I had forgotten your magnum opus.

 

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

Re: building a histogram

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

Re: building a histogram

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.  

Re: building a histogram

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
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."