Silverfrost Forums

Welcome to our forums

Math Errors?

6 Sep 2006 8:47 #992

I have a piece of software originally written as a standalone program that I have turned into a dll using FTN95. It now recieves variables from a namelist file created by visual basic, and runs some computations. The standalone program is fine, it's been working for years. The variables pass in correctly, I've tested that. However, when the computations start, I'm getting ridiculous math errors in equations that I never changed, ones that I literally copied and pasted, save for some syntax changes such as line continuations. Take this block of code for example:

Do 90, INC = 1, INC1
          RAD = DEG / 57.296
          
          MAINVALS(INDEX,1) = DEG
          PINVALS(INDEX,1) = DEG
          XHVALS(INDEX,1) = DEG
          SHOEVALS(INDEX,1) = DEG          

          SN = R * SIN(RAD)
          CO = SQRT((L ** 2 - (R * SIN(RAD)) ** 2))
          Call SUB530(ANG, SN, CO)
          FEE = ANG
          FT1 = NRL1(INC) * SIN(RAD) * (1 + COS(RAD) / ((L / R) ** 2 -  SIN(RAD) ** 2) ** .5)
          FT2 = NRL2(INC) * SIN(RAD) * (1 + COS(RAD) / ((L / R) ** 2 -  SIN(RAD) ** 2) ** .5)
          FR1 = NRL1(INC) * (COS(RAD) - (SIN(RAD)) ** 2 / ((L / R) ** 2 - SIN(RAD) ** 2) ** .5) - 0.0000284 * R * N ** 2 * WRT
          FR2 = NRL2(INC) * (COS(RAD) - (SIN(RAD)) ** 2 / ((L / R) ** 2 - SIN(RAD) ** 2) ** .5) - 0.0000284 * R * N ** 2 * WRT
          FRC1 = NRL1(INC) * (COS(RAD) - SIN(RAD) ** 2 / ((L / R) ** 2 - SIN(RAD) ** 2) ** .5) - 0.0000284 * R * N * N * (WRT - CP)
          FRC2 = NRL2(INC) * (COS(RAD) - SIN(RAD) ** 2 / ((L / R) ** 2 - SIN(RAD) ** 2) ** .5) - 0.0000284 * R * N * N * (WRT - CP)
          RA = (90.0 - FEE - DEG) / 57.296
          FC1Y = -FRC1 * COS(RA) + FT1 * SIN(RA)
          FC1X = -FRC1 * SIN(RA) - FT1 * COS(RA)
          FC1 = SQRT((FC1X ** 2 + FC1Y ** 2))
          FC2Y = -FRC2 * COS(RA) + FT2 * SIN(RA)
          FC2X = -FRC2 * SIN(RA) - FT2 * COS(RA)
          FC2 = SQRT((FC2X ** 2 + FC2Y ** 2))
          SN = FC1Y
          CO = FC1X

Starting with RAD = 0 or DEG = 90, obviously sin and cosine should be 0 and 1 respectively. Thus, as you'd expect, FT1 and FT2 are also 0. Now comes the first error... When FR1 is calculated using NRL1(1) = 15467 and rad still 0, you should get -15470.3 according to my hand calculations, maybe I made a mistake maybe I didn't, there are still others, but either way, the computer returns -18404.2. However, the most interesting one I have found is at the point where it calculate FC1Y or FC1X etc... Upon performing this calculation the first time, you have RA = 90 - FEE - DEG ( take my word that FEE and DEG are both, and correctly so, 90) and thus equal to 0. thus RA is PI/2 and cos is 0 and sin is 1. Therefore, since FT1 is 0 from earlier, and cos is 0, FC1Y should be -FRC1*0 + 0 * 1 which is 0. But to my surprise, I've discovered that 0+0 is now .107879. Now, if this were a smaller error, I could attribute it to rounding error, truncation, etc... But it's a fairly significant difference, and it's by far not the only occurance of it. What

6 Sep 2006 9:00 #993

do you think is going on?

7 Sep 2006 12:24 #994

This may be trivial, but like Bruce's comment on **0.5 I always thought that it was better programming practice to also avoid using **2 as well

7 Sep 2006 1:38 #995

John

Have you tested the code using /CHECKMATE?

Is it possible that line continuations have gone wrong? For example, with fixed format Fortran it is possible to have a valid equation but part of it is actually commented out.

If you can post a very short working example of the problem then fault should be easy to find.

Please login to reply.