Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Ankündigungen
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Diskussionen

Calculate Median Value for Real number

uddin__md
Einsteiger
4.069Aufrufe

I wrote a program for the calculate the media value of real numbers. Program calculate the median value, but the calculated median value does not similar to excel or spss calculated median value. The excel gave median value 27.21 for the input data, but the program gave 29.45 for same input data. I also tried using integer or other data set the program also gave different median value from others.

Please give a solution How can I solve this issues. Many thanks for your support. 

Beschriftungen (1)
0 Kudos
1 Lösung
andrew_4619
Geehrter Beitragender III
4.020Aufrufe
   REAL, DIMENSION(0:100)			:: X
   INTEGER                          :: N
   INTEGER                          :: IOstatus
   INTEGER                          :: i
   OPEN(1,FILE ='DATA07.DAT', STATUS = 'OLD') 
   DO
      READ(1,*,IOSTAT=IOstatus) N, (X(i), i = 1, N)

I was noting the array X start at x(0) through to x(100) , that is 101 elements but in your loop you have i = 1, n that is i does not start at zero.  Was that what you intended? X(0) is not set.

Lösung in ursprünglichem Beitrag anzeigen

11 Antworten
JohnNichols
Geschätzter Beitragender III
4.058Aufrufe
IF (MOD(N,2) == 0) THEN           ! compute the median
         Median = (Temp(N/2) + Temp(N/2+1)) / 2.0
      ELSE
         Median = Temp(N/2+1)
      END IF

At a guess and I do not do median -- these are wrong -- you are probably missing a bra and a ket as we say in Pure Math - could be wrong 

uddin__md
Einsteiger
4.043Aufrufe

@JohnNichols  Previously I used this format, then I changed it. But Both format output was given similar errors. Many thanks and looking further solution 

John_Campbell
Neuer Beitragender II
3.964Aufrufe

Shouldn't the median value be an element of the set of values, unlike the average ?

You could choose either possibility when the count is even.

Arjen_Markus
Geehrter Beitragender II
3.926Aufrufe

Not necessarily, the definition at Wikipedia, https://en.wikipedia.org/wiki/Median, includes the average of two numbers in the sequence, f you have an even amount of data.

andrew_4619
Geehrter Beitragender III
4.056Aufrufe

I didn't study the program much but I noted that your array is zero based but all your loops look at elements 1 to N rather than 0 to n-1 is that your problem?

 

 

uddin__md
Einsteiger
4.042Aufrufe

@andrew_4619  Your explanation may not clear. Many thanks for your reply. If you have more energy please give me a solution

Steve_Lionel
Geehrter Beitragender III
4.036Aufrufe

This looks to me like a class work assignment. If so, you should not be asking others to do your work for you.

uddin__md
Einsteiger
4.023Aufrufe

@Steve_Lionel  Dear Steve,  this is not class work. I try to write a program for WQI model. That is a another part of my module. 

Steve_Lionel
Geehrter Beitragender III
4.020Aufrufe

Ok - the code you had and the problem reminded me of class assignments.

andrew_4619
Geehrter Beitragender III
4.021Aufrufe
   REAL, DIMENSION(0:100)			:: X
   INTEGER                          :: N
   INTEGER                          :: IOstatus
   INTEGER                          :: i
   OPEN(1,FILE ='DATA07.DAT', STATUS = 'OLD') 
   DO
      READ(1,*,IOSTAT=IOstatus) N, (X(i), i = 1, N)

I was noting the array X start at x(0) through to x(100) , that is 101 elements but in your loop you have i = 1, n that is i does not start at zero.  Was that what you intended? X(0) is not set.

uddin__md
Einsteiger
4.002Aufrufe

@andrew_4619  Many thanks for your feedback. I solved this problem with array size correction.

Antworten