Mathematical functions power

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #30535 quote
    Broc
    Participant
    Average

    Is there a Prorealtime POWER math function e.g.

    y = x^3  as in 4^3 = 64?

    #30539 quote
    Nicolas
    Keymaster
    Master

    Unfortunately no, this is a already a query for new instruction in the users wish list: https://www.prorealcode.com/topic/centralization-of-queries-and-suggestions-on-prorealtime/

    The best you could do to get the result of this math function is by making a loop like this:

    number=4
    pow=3
    
    result=0
    i=1
    while i<pow do
     if i=1 then 
      result=number
     endif 
     result=result*number
     i=i+1
    wend
    
    return result

    Let me know if it’s clear for you.

    #30547 quote
    Broc
    Participant
    Average

    Hi Nicolas

    Thanks for the prompt reply!

    I have found a mathematical equivalent if the Prorealtime LOG function (called Napierian log in the manual) is actually the common LN function:

    y = x^p = e^(p*LN(x))

    This could then be coded as:

    y = EXP(p*LOG(x))

    This works fine.

    W

    Nicolas, zilliq, Maz and 3 others thanked this post
    #30680 quote
    zilliq
    Participant
    Master

    Thanks for your answer wessel 😉

    How did you know that ?

    laurenzo thanked this post
    #30778 quote
    Broc
    Participant
    Average

    I had to do a bit of math research…  Prorealtime could use this formula to create an easy power math function.

     

    B-)

    zilliq and Wing thanked this post
    #34416 quote
    Maz
    Participant
    Veteran

    facepalm

    #34426 quote
    Maz
    Participant
    Veteran

    I have a power function like this?

    // n = 2
    // x = 3
    // r = n^x
    
    once j = x-1
    
    r = n
    if x > 0 then
    for  i = 1 to j do
    r = (r * n)
    next
    else
    for  i = 1 to j do
    r = (r / n)
    next
    endif
    
    return r
    
    Nicolas thanked this post
    #34428 quote
    Maz
    Participant
    Veteran

    Here’s tanh (subsequently sinh and cosh)

     

    // x = 2
    // result = tanh(x)
    
    once e  = exp(1)
    mx = x * -1
    eX  = CALL fnPower[e, x]
    eXm = CALL fnPower[e, mx]
    
    sinh = 0.5* (eX - eXm)
    cosh = 0.5* (ex + eXm)
    tanh = sinh / cosh
    
    return tanh

     

    See above for powers

    Nicolas and Wing thanked this post
    #34439 quote
    Nicolas
    Keymaster
    Master

    Great job Maz!

    Maz thanked this post
    #34483 quote
    Maz
    Participant
    Veteran

    You’re welomce; unfortunately it’s very slow but that’s all we have for now 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Mathematical functions power


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Broc @wessel Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by Maz
8 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/31/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...