dryb38654 2014-08-21 07:29
浏览 48

在PHP中实现ERF功能

I want to implement an ERF function in PHP. I got its formula from wikipedia

P_Value = 1-  (  ERF ( ABS ( Residual –mean ) )/(√2*SD )

I didn't get the idea how to implement it in PHP.

  • 写回答

2条回答 默认 最新

  • duanjie2701 2014-08-21 07:45
    关注

    Based on the formula you provided, only the ERF (Error function) part should look like this:

    function ERF ($difference) {
        return abs($difference);
    }
    

    Now call $value = ERF($residual - $mean); from anywhere inside a php script to store the ERF value in the $value variable.

    Edit: Let's assume you meant this formula:

    enter image description here

    So, it should be:

    function ERF ($ll, $ul, $t, $dt, $dx) {
         $val = 0;
         for($i = $ll; $i <= $ul; $i+=$dx){
              $val +=  exp(-pow($t,2)) * $dt;
         }
         return (2/sqrt(pi())) * $val;
    }
    

    now call, $value = ERF(0, $x, $t, $dt, $dx); where $x is the upper limit, $t is the time and $dt is the dt part of integration as in time interval.

    Note: I've added another parameter $dx here because it is an integral for continuous domain and $dx, $dt both should be very close to 0 for better approximations. For discrete values, you can provide both $dx and $dt as 1. And that would rather be called summation than integral.

    For better approximation on integration, see Numerical integration algorithms and techniques.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测