CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: mathematical equation implmentation in c++

  1. #1
    Join Date
    May 2015
    Posts
    245

    mathematical equation implmentation in c++

    Hello,

    I need to implement the following math conversion in the c++. I am looking for simple function. Could you help me with this., I am not much aware of the maths functionalities available in c++

    1. Need to convert dBns to ns and the in the xml requirements, I see the formula as : 10^(0.8 * x)

    2. Other conversion is similar(mBradians to radians) : 10 ^ (0.001 * x)
    Then I need the convert the radians to degrees

    Thanks a lot
    pdk
    Last edited by pdk5; April 30th, 2020 at 07:16 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,725

    Re: mathematical equation implmentation in c++

    What is dBns? ns? mBradians?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    Quote Originally Posted by VictorN View Post
    What is dBns? ns? mBradians?
    DeciBel nano Secs to Nano Secs. It may not be much relevance as the conversion formula is shown above .
    I just want to implement the conversion formula in c++

  4. #4
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    And the conversion formula is in the excel. Any idea, the symbol "^" mean in excel ?
    It is very help ful if I get this info as soon as possible as I have release next week !

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,725

    Re: mathematical equation implmentation in c++

    It is the same as function power()
    Victor Nijegorodov

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: mathematical equation implmentation in c++

    For C++, use pow() function instead of ^ http://www.cplusplus.com/reference/cmath/pow/

    so 10 ^ (0.8 * X) becomes pow(10, 0.8 * X). And similar for the other.

    To convert radians to degrees (and vice versa), always remember that 360 deg = 2 * pi radians. So 1 radian is 360 / (2 * pi) degrees which is 180 / pi degrees. So y radians are y * 180 / pi degrees.

    To get the value of pi without having to define a constant, use the value of M_PI as explained in https://docs.microsoft.com/en-us/cpp...s?view=vs-2019
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  7. #7
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    Thankyou very much Kaud. Very helpful .

  8. #8
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    Another doubt generic not c++ :
    To convert nsDb to ns, the formula given is dBns to ns : 10^(0.8 * x) .

    From the look of it, it does not look right ?

    Because the other formula, (mBradians to radians) : 10 ^ (0.001 * x) looks ok, because the mB = .001 Bell

    my maths skills have been rusty, so very helpful to get some inputs here.
    Last edited by pdk5; May 1st, 2020 at 09:42 AM.

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: mathematical equation implmentation in c++

    decibel - or bel - has got not nothing to do with time or angles and everything to do with power ratios. radians/degrees has got nothing to do with (deci)bel. A decibel is 1/10 of a bel.

    See https://en.wikipedia.org/wiki/Metric_prefix for a list of SI prefixes.

    To do a conversion from one type to another, they must be a mathematical relationship between them. ie there is one between radians and degrees, but not between decibel and sec(ond)s.

    What are you trying to do? You said in post #3 that you had the formulas and all you needed was help implementing them? If the formulas are now not correct, you need to determine what the original number represents in terms of a unit (mass, length, time etc) and its prefix. Then determine what the required number is to represent. Once you know that, then the required conversion formula can be obtained.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  10. #10
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    Thanks a lot kaud , for the reply . These formulas are provided in requirements. But req are in initial stages and may not be correct.

    The formula I showed above , 10^(0.8 * x) , is to convert "nanoSecond DB" to "nanosecond" ? Looks incorrect and even sample values were coming very high. so I am thinking it may be some typo in requirements ?
    Last edited by pdk5; May 1st, 2020 at 02:34 PM.

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: mathematical equation implmentation in c++

    If DB is for Decibel, then nanoSecond Decibel is a nonsense. A nano Decibel would make sense which would be 10 ^ -10 Bel. But in physical terms, that's such a very low power level that something doesn't seem right.

    Where are these formulas coming from? What exactly are you trying to do?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  12. #12
    Join Date
    Feb 2017
    Posts
    536

    Re: mathematical equation implmentation in c++

    Quote Originally Posted by pdk5 View Post
    To convert nsDb to ns, the formula given is dBns to ns : 10^(0.8 * x) .

    From the look of it, it does not look right ?

    Because the other formula, (mBradians to radians) : 10 ^ (0.001 * x) looks ok, because the mB = .001 Bell
    Note that there's a slight difference of notation between dBns and mBradians.

    It's easier to see if you rewrite these like dB(ns) and mB(radians). The first would be the dB value corresponding to a ratio relative to 1 nanosecond. The second would be the mB value corresponding to a ratio relative to 1 radian. It could explain why the formulas do not conform logically.
    Last edited by wolle; May 2nd, 2020 at 05:06 AM.

  13. #13
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    Quote Originally Posted by 2kaud View Post
    If DB is for Decibel, then nanoSecond Decibel is a nonsense. A nano Decibel would make sense which would be 10 ^ -10 Bel. But in physical terms, that's such a very low power level that something doesn't seem right.

    Where are these formulas coming from? What exactly are you trying to do?
    - The "nanosec DB" is the unit received for the Delay spread in the LTE/5g at a pixel from the basestation. In our tool, they want to display with the unit of microseconds. rather than nanosec DB. I have not much worked on Physical layer stuff. But even then , this unit looks bit odd for me. I mean to use DB on nanosecs ?


    - And the other unit is from "mBradians" to "radians" is for the Angular spread data .
    Last edited by pdk5; May 2nd, 2020 at 07:41 AM.

  14. #14
    Join Date
    Feb 2017
    Posts
    536

    Re: mathematical equation implmentation in c++

    ... continuing from #12:

    The second formula would be

    x = 1000 * log(ratio) // mB formula

    =>

    ratio = 10 ^ (x/1000)

    so it looks right.
    Last edited by wolle; May 3rd, 2020 at 07:50 AM.

  15. #15
    Join Date
    May 2015
    Posts
    245

    Re: mathematical equation implmentation in c++

    Quote Originally Posted by wolle View Post
    The second formula would be

    x = 1000 * log(ratio)

    =>

    ratio = 10 ^ (x/1000)

    Thanks , but whatabout the first one ?

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)