Computations using minimum values


 
Thread Tools Search this Thread
Top Forums Programming Computations using minimum values
# 1  
Old 08-02-2013
Computations using minimum values

I have the following code and into into trying to simplifying it. Any suggestions please?

Code:
  pmin = min (p(1), p(2), p(3), p(4), p(5), p(6))

  ni = 0
  xint = 0.0
  yint = 0.0
  zint = 0.0

  !--------------------------------------------- !

  if ((0.99999 * p(1)) <= pmin) then
    xint = x1i
    yint = yp + (yg * p(1))
    zint = zp + (zg * p(1))
    ni = ni + 1
    ic = ic - 1
  else if ((0.99999 * p(2)) <= pmin) then
    xint = x2i
    yint = yp + (yg * p(2))
    zint = zp + (zg * p(2))
    ni = ni + 1
    ic = ic + 1
  end if

  !--------------------------------------------- !

  if ((0.99999 * p(3)) <= pmin) then
    xint = xint + (xp + (xg * p(3)))
    yint = yint + y3i
    zint = zint + (zp + (zg * p(3)))
    ni = ni + 1
    jc = jc - 1
  else if ((0.99999 * p(4)) <= pmin) then
    xint = xint + (xp + (xg * p(4)))
    yint = yint + y4i
    zint = zint + (zp + (zg * p(4)))
    ni = ni + 1
    jc = jc + 1
  end if

  !--------------------------------------------- !

  if ((0.99999 * p(5)) <= pmin) then
    xint = xint + (xp + (xg * p(5)))
    yint = yint + (yp + (yg * p(5)))
    zint = zint + z5i
    ni = ni + 1
    kc = kc - 1
  else if ((0.99999 * p(6)) <= pmin) then
    xint = xint + (xp + (xg * p(6)))
    yint = yint + (yp + (yg * p(6)))
    zint = zint + z6i
    ni = ni + 1
    kc = kc + 1
  end if

# 2  
Old 08-02-2013
Looks minimal already! Does it work?
# 3  
Old 08-02-2013
That's good, just needed opinion. Thanks
# 4  
Old 08-02-2013
When searching for min, use < not <= since there is usually no point in overwriting one just as small, only smaller.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

2. Shell Programming and Scripting

Output minimum and maximum values for replicates ID

Hi All I hope that someone could help me! I have an input file like this, with 4 colum(ID, feature1, start, end): a x 1 5 b x 3 10 b x 4 9 b x 5 16 c x 5 9 c x 4 8 And my output file should be like this: a x 1 5 b x 3 16 c x 4 9 What I would like to do is to output for each ID... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

3. Shell Programming and Scripting

Comparing the minimum values of a character in lines

Hello, I have files as follows: ACTGCCCTG ACCGGCTCC ACAAATTTC ACCCGGGTTI want to do the following: I want to find certain strings in each line, for example CT and TT. Then I want the script to give me the number of the characters before my string, for example, 6 for the first line, 5 for... (4 Replies)
Discussion started by: Homa
4 Replies

4. Shell Programming and Scripting

Print minimum and maximum values using awk

Can I print the minimum and maximum values of values in first 4 columns ? input 3038669 3038743 3037800 3038400 m101c 3218627 3218709 3217600 3219800 m290 ............. output 3037800 3038743 m101c 3217600 3219800 m290 (2 Replies)
Discussion started by: quincyjones
2 Replies

5. Shell Programming and Scripting

Find minimum value different from zero

Hello, I have this file file1.csv Element1;23-10-2012;1,450;1,564;1,428 Element2;23-10-2012;1,448;1,565;1,427 Element3;23-10-2012;1,453;1,570;1,424 Element4;23-10-2012;1,428;1,542;1,405 Element5;23-10-2012;1,461;;1,453 Element6;23-10-2012;1,438;1,555;1,417... (6 Replies)
Discussion started by: saba01
6 Replies

6. UNIX for Dummies Questions & Answers

Numeric computations in bash

I am on Ubuntu 11.10 using bash. I want to perform some numeric computations and have the following options: # Setting verbosity levels none=0; low=1; medium=2; high=3; debug=4 (( vbLevel=medium )) if (( vbLevel > low )); then echo "Test 1, $vbLevel" fi vbLevel=$medium if ];... (3 Replies)
Discussion started by: kristinu
3 Replies

7. Shell Programming and Scripting

Computations on a text file

hey, I have text file which has some data for some device Id's. i want to perform AVG, MAX,2nd MAX on these device ids. The .txt file looks like below. please help me in finding the computations per Device id. My output file should contatin with DeviceID,Avg, max and 2nd max of the device ID.... (8 Replies)
Discussion started by: mahi_mayu069
8 Replies

8. UNIX for Dummies Questions & Answers

Extract minimum values among 3 columns

Hi. I would like to ask for helps on extracting a minimum values among three columns using gawk in tab separator. input file: as1 10 20 30 as2 22 21 23 as3 300 391 567 as4 19 20 15 Output file: as1 10 as2 21 as3 300 as4 15 I am extremely appreciate your helps and comments.... (2 Replies)
Discussion started by: Amanda Low
2 Replies

9. Programming

Select several minimum values from row (MySQL)

Hello there. I've got the query like that SELECT count(tour_id) AS cnt FROM orders JOIN tours ON orders.tour_id=tours.id GROUP BY tour_id The result Is cnt 1 4 2 1 1 Now i have to select all records with minimum values in field "cnt" MySQL function min() returns only one.... (2 Replies)
Discussion started by: Trump
2 Replies

10. Shell Programming and Scripting

Insert rows with computations of next row

Hello folks, I have data collected in every 3 hours. But, I would like to expand this to 1 hour interval by equally dividing with next row. For example, I want to keep the first value 1987-01-01-00z 2.0, but following all record should be re-written as follow. 1987-01-01-03z 5.0 becomes... (11 Replies)
Discussion started by: Jae
11 Replies
Login or Register to Ask a Question