Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development Tools (Compilers, Debuggers, Profilers & Analyzers)
- Intel® Fortran Compiler
- Calculate Median Value for Real number

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

uddin__md

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
08:39 AM

683 Views

Calculate Median Value for Real number

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.

1 Solution

andrew_4619

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
04:10 PM

634 Views

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

Link Copied

11 Replies

JohnNichols

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
08:44 AM

674 Views

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

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
10:46 AM

657 Views

John_Campbell

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-20-2020
11:46 PM

578 Views

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

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-25-2020
12:45 AM

540 Views

andrew_4619

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
08:52 AM

670 Views

uddin__md

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
10:48 AM

656 Views

Steve_Lionel

Black Belt Retired Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
10:55 AM

650 Views

uddin__md

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
03:47 PM

637 Views

Steve_Lionel

Black Belt Retired Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
03:49 PM

634 Views

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

andrew_4619

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
04:10 PM

635 Views

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

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2020
05:13 PM

616 Views

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

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.