douchuopiao9002 2017-01-12 07:43
浏览 57
已采纳

Golang中模拟钟形曲线上的值

My math is a bit elementary so I apologize for any assumptions in advance.

I want to fetch values that exist on a simulated bell curve. I don't want to actually create a bell curve or plot one, I'd just like to use a function that given an input value can tell me the corresponding Y axis value on a hypothetical bell curve.

Here's the full problem statement:

I am generating floating point values between 0.0 and 1.0.

0.50 represents 2.0 on the bell curve, which is the maximum. The values < 0.50 and > 0.50 start dropping on this bell curve, so for example 0.40 and 0.60 are the same and could be something like 1.8. 1.8 is arbitrarily chosen for this example, and I'd like to know how I can tweak this 'gradient'.

Right now Im doing a very crude implementation, for example, for any value > 0.40 and < 0.60 the function returns 2.0, but I'd like to 'smooth' this and gain more 'control' over the descent/gradient

Any ideas how I can achieve this in Go

  • 写回答

1条回答 默认 最新

  • duanji7881 2017-01-12 08:07
    关注

    Gaussian function described here : https://en.wikipedia.org/wiki/Gaussian_function
    has a bell-curve shape. Example of implementation :

    package main
    import (
        "math"
    )
    
    const (
        a = 2.0 // height of curve's peak
        b = 0.5 // position of the peak
        c = 0.1 // standart deviation controlling width of the curve 
                //( lower abstract value of c -> "longer" curve)
    )
    
    func curveFunc(x float64) float64 {
        return a *math.Exp(-math.Pow(x-b, 2)/2.0*math.Pow(c, 2))
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办