Menu

The mathematical constant e

Mikam
2015-12-17
2015-12-18
  • Mikam

    Mikam - 2015-12-17

    Hi
    The mathematical constant e, also called Euler's constant, is the base of the Exp and Log where e=2.718.
    i.e 2.718 e 4.607 = 100.27
    Is their any way using GCB to execute this function.
    Thanks in advance

     
  • Anobium

    Anobium - 2015-12-17

    Yes, I think so. If you can calculate e in integer maths then we can.

    Look on the web for some example of where this has been done in the past, for other languages, then, the port to GCB should be relatively simple.
    If you have v0.94 (any of the release candidates) or v0.95 or greater looks at your \GreatCowBasic\Include folder . You will see maths.h and trig[n]places.h these are the current release of how we use integer maths to provide factorised results.

     
  • Mikam

    Mikam - 2015-12-17

    Although the first part is straightforward i.e 4 where 2.718 multiplies itself 4 times=54.598, i am not able to derive the 0.607 to into the equation for GCB. to give the final value of 100.27.
    Sorry if i being a bit thick on this one.

     
  • Anobium

    Anobium - 2015-12-17

    Attach the code you have please. Add lots of comments so we cam help.

     
  • Mikam

    Mikam - 2015-12-17

    ~~~~
    ;Chip Settings

    chip 16F887,8

    ;Defines (Constants)

    define LCD_IO 8

    define LCD_RW PORTD.6

    define LCD_Enable PORTD.7

    define LCD_RS PORTD.5

    define LCD_DATA_PORT PORTB

    ;Variables
    Dim OA, OB, OC, i, j As long
    Dim answer As long

    '#include <maths.h>
    'Dim p_base As byte
    'ver 17dec15.a
    'GCGB v0.94.28 2015-11-23 (When compling)
    '
    main:
    'j is derived from x-y curve, this value can be from 0 to 5
    'values would be multiplied to remove the decimal point

    'The difficulty for me is to use the remaining constant e=0.6
    'The answer should be around 100000
    i=2.781 'Constant e
    j=4.6

    OA=(27812781)/1000
    OB=(OA
    2781)/1000
    OC=(OB*2781)/1000
    locate 0,0
    print OA
    locate 1,0
    print OB
    locate 2,0
    print OC

    wait 1 S
    goto main

    '*
    the display shows
    7733
    21505
    59805

     

    Last edit: Anobium 2015-12-17
  • Anobium

    Anobium - 2015-12-17

    You will have to remind me. How do we resolve the remaining 0.6? What is the mathematical intent?

     
  • Bert

    Bert - 2015-12-18

    (from Stackoverflow.com) Express the exponent as fraction and separate both parts (if the numbers get too big, you can use continued fraction expansion to get a good approximation):

    4.6 = 46/10 = 23/5

    10^4.6 = 10^(23/5) = (10^23)^(1/5)

    The integer parts shouldn't be a problem (see http://en.wikipedia.org/wiki/Exponentiation_by_squaring). Then you can calculate the root by one of the algorithms described here: http://en.wikipedia.org/wiki/Nth_root_algorithm

     

    Last edit: Bert 2015-12-18
  • Anobium

    Anobium - 2015-12-18

    Excellent. gcb supports sqroot so this is a practical approach.

     
  • Mikam

    Mikam - 2015-12-18

    Thanks for your guidance. I will give it a go.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.