Recent

Author Topic: Matrix  (Read 1945 times)

Don_Zagor

  • New Member
  • *
  • Posts: 25
Matrix
« on: December 18, 2018, 04:04:28 pm »
I need to find the arithmetic mean of minimum elements from every column.
My algorithm goes like this:
Set the minimum to be the first element of the column, then compare this element to other column elements and find the minimum of one column. After that go to the next column an set the minimum to be the first element of the second column. Then find the minimum element of that column. Repeat this for the number of columns the matrix has. Every time I find the minimum of a column I add it to some variable for example number. And then number is the the sum of all minimums. After I only divide variable number with number of columns.
I am not near a computer so can someone review this algorithm and tell me if it is any good?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Matrix
« Reply #1 on: December 18, 2018, 04:16:25 pm »
Don't forget to initialize the variable that holds the sum of the column minima.
Depending on the quality of your data you may need to insert a policy for dealing with missing cell values, or non-numeric or nonsense values.

Don_Zagor

  • New Member
  • *
  • Posts: 25
Re: Matrix
« Reply #2 on: December 18, 2018, 04:25:55 pm »
So this could work?

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Matrix
« Reply #3 on: December 18, 2018, 04:37:18 pm »
Don't forget to examine the math unit: all kinds of mean.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Matrix
« Reply #4 on: December 18, 2018, 06:16:01 pm »
So this could work?

Yes. Just initialize the sum to zero as suggested.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Matrix
« Reply #5 on: December 18, 2018, 06:28:35 pm »
Don't forget to examine the math unit: all kinds of mean.

Any particularly nasty ones I should be aware of?
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Matrix
« Reply #6 on: December 18, 2018, 06:49:46 pm »
Don't forget to examine the math unit: all kinds of mean.
I would not advertise this too loudly: because math's Mean functions take an array or the pointer to the first value of a contiguous memory block as parameter, people will copy their data into an array just to be able to apply one of these ready-made functions.

Being able to calculate of the mean value of some numbers without calling a pre-fabricated function is one of the basic capabilities a programmer must have.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Matrix
« Reply #7 on: December 19, 2018, 02:51:59 pm »
all kinds of mean

Thanks wp, I get it now (I took "all kinds of mean" as "lots of bad stuff", US slang) :D

Never used math.mean
« Last Edit: December 19, 2018, 03:09:29 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

 

TinyPortal © 2005-2018