dpkk8687 2014-08-06 14:47
浏览 18

PHP中的科学计算

i have a client that wants to turn this calculation into a function in PHP. i been given test numbers with an answer for it and i am out from this answer by too much for it to be correct im not sure if the calculation is wrong or im just not seeing the issue.

Scientific Calculation

function Density($m1 , $m2, $m3, $pw, $psm){

  return   $m1 /  (($m2 - $m3) / $pw) - (($m2 - $m1) / $psm) ; 
} 
$Density = ( Density(746.2, 761.7, 394.6, (998.1*1000), (761.7-746.2)) / 1000000)

output : 2.02882553228
answer : 2.127

also i have tried it like this as well but this is way far out for it to be right

function Density($m1 , $m2, $m3, $pw, $psm){

  return   $m1 /  ((($m2 - $m3) / $pw) - (($m2 - $m1) / $psm )); 
} 

output : -0.001
answer : 2.127

i know it should be as close to the answer as it can get 0.010 out fromthe correct answer but i dont see what im doing wrong please help internet.

  • 写回答

2条回答 默认 最新

  • dongnuo6310 2014-08-06 14:51
    关注

    Remember BEDMAS - brackets exponents division multiplication addition subtraction. Your code is wrong for the order-of-operations:

    m1 / (((m2 - m3) / pw) - ((m2 - m1) / psm))
    

    or, if that equation had been typeset properly:

              m1
     --------------------
     m2 - m3      m2 - m1
     -------  -   -------
        pw          psm
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错