IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Reg: Exponential statement in Cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chowdhrykapildev

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Wed Jul 27, 2011 6:33 pm
Reply with quote

Hi,

I have a requirement where I need to code the below statement in Cobol.

Code:
Adjusted_score = 1 / ( 1 + exp( -log( (unadj_riskscore) / (1 - (unadj_riskscore) ) ) - AF_new ) );

Can someone help me how can I do this in a Compute Statement?

Thanks,
KC
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 6:43 pm
Reply with quote

Look at what mathematical intrinsic functions are available.

Split it into more than one compute, into "logical" smaller parts. Make sure you know about how the compute treats intermediate values, and take account of that in data definitions.

Come back if you get stuck.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 27, 2011 7:18 pm
Reply with quote

Which version of COBOL ar eyou using? Assuming you're using Enterprise COBOL, the LOG function is available. You will have to use exponentiation with whatever value of e you deem acceptable as a substitute for the EXP function.
Back to top
View user's profile Send private message
chowdhrykapildev

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Wed Jul 27, 2011 8:24 pm
Reply with quote

Hi,

Thanks for your replies.

I had coded in the below way but unable to confirm whether it is correct or not.

Code:
     COMPUTE Adjusted_score ROUNDED                       
          = 1 / ( 1 + ( WS-E ** ( -                     
                   FUNCTION LOG ( ( unadj_riskscore)   
              / (1 - ( unadj_riskscore) ) ) -           
              AF_new ) ) )                       
    ON SIZE ERROR                                       
      MOVE 'PROBQUE ' TO WS-ON-SIZE-ERROR-NAME         
  END-COMPUTE


where WS-E is defined as below:
Code:
05  WS-E                        COMP-2                     
                   VALUE      +2.71828182845904E+00.   

The compilation and even the execution of the pgm went fine.
But I'm still having a doubt whether what has been mentioned in the requirement and the above Compute statement does the same calculation or is that I had missed something here in Cobol ?

Thanks,
KC.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 27, 2011 8:44 pm
Reply with quote

What causes you to doubt the COBOL results? Unless you have something causing you to doubt the computer results (be they from COBOL, SAS, PL/I, ASSEMBLER, or whatever), you should accept that the computer knows how to do arithmetic. The results may or may not be accurate enough, depending upon such things as intermediate resutls (in COBOL), but the computer will do the calculation however you coded it.

If you're asking whether or not you used the right formula, or coded it correctly in COBOL -- how could we possibly know that? That would require you to go back to the program specifications and compare your results and code to them.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 8:59 pm
Reply with quote

Hello,

Suggest you do a few of these calculations "by hand" (using a calculator) and compare the results to the output from your code. . .

If they are the same - you're probably good to go.

If not, resolve. . .
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 10:36 pm
Reply with quote

I agree with Robert and Dick. There's not much we can do with what we have.

You presumably have an actuary or loss-adjustor behind this calculation, so make friends with them and ask them to help you work through some examples to check out the code. You'll learn a lot at the same time.

I would say in your original you specify -log, which is different from what you have coded in the compute (which is subtract the log) but I don't know which, if either, is a typo.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Jul 27, 2011 11:05 pm
Reply with quote

I don't know COBOL instrinct functions, but does LOG use base 10 or base e?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 11:10 pm
Reply with quote

Excellent question. It has LOG10 and LOG.

So LOG is base e. Useless guess following deleted.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top