- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个具有对数缩放功能的 slider 来控制麦克风 RMS 阈值。
我写的下面的函数可能很糟糕(数学不是我的强项),但似乎确实可以实现我想要的对数缩放。但是,我现在需要在使用刻度的条形图中显示 RMS 级别,因此我需要反转此函数。
const rmsLogarithmicScale = (value, max) => {
const log = ((100 - (Math.log((1 - value) * 100) / 4.605170185988092) * 100) / 100) * max;
return log === Infinity ? max : log;
};
console.log(rmsLogarithmicScale(0.5, 0.05)); // Result: 0.007525749891599539
console.log(rmsLogarithmicScale(0.5, 300)); // Result: 45.15449934959723
const rmsLogarithmicScaleInverse = (rms, max) => {
// I have literally no idea where to start...
}
rmsLogarithmicScaleInverse(0.007525749891599539, 0.05); // Result: 0.5
有没有一位好心的数学家可以帮助我解决这个问题?
最佳答案
在 @Bergi 建议我尝试简化原始函数后,我以 @Andy 的风格重写了该函数,并成功地反转了它。
You should start by simplifying to const log = -Math.log(1 - value) / Math.log(100) * max; — Bergi
const logScale = (value, max) => {
const x1 = 1 - value;
const x2 = -Math.log(x1);
const x3 = x2 / Math.log(100);
const x4 = x3 * max;
return x4;
};
const altInverseRmsLogScale = (lg, max) => {
const x4 = lg / max;
const x3 = x4 * Math.log(100);
const x2 = Math.exp(-x3);
const x1 = 1 - x2;
return x1;
};
console.log(logScale(0.7, 300)); // 4.727557716909737
console.log(inverseLogScale(logScale(0.7, 300), 300)); // 0.07000000000000006
简洁版本
const logScale = (value, max) => (-Math.log(1 - value) / Math.log(100)) * max;
const inverseLogScale = (lg, max) => 1 - Math.exp(-(lg / max * Math.log(100)));
简洁版本
const logScale = (value, max) => (-Math.log(1 - value) / Math.log(100)) * max;
const inverseLogScale = (lg, max) => 1 - Math.pow(100, -lg / max);
console.log(logScale(0.6, 300));
console.log(inverseLogScale(logScaleTwo(0.6, 300), 300));
https://repl.it/@sarcoma/log-scale
最终函数
我还需要处理 value === max
时返回的 Infinity
。
const logScale = (value, max) => {
const log = (-Math.log(1 - value) / Math.log(100)) * max;
return log === Infinity ? max : log;
};
const inverseLogScale = (lg, max) => 1 - Math.pow(100, -lg / max);
关于javascript - 麦克风输入电平的对数函数的反函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60477788/
我需要知道这个 js 代码有什么错误,我需要点击展开 div 并在第二次点击时 div 回到原来的尺寸这是javascript: function myBurger() { document
id 内置函数是否有反向或反向?我正在考虑使用它来编码和解码字符串,而不会像 PyCrypto 库那样花费太多时间或大量开销。我的需求非常简单,所以我不想使用 PyCrypto 进行简单的编码和解码。
如何将urllib.urlencode处理后的数据转成dict?urllib.urldecode 不存在。 最佳答案 作为 the docs对于 urlencode 来说, The urlparse
我正在使用 Gekko 为一组 react 动力学选择 A 最优实验。目标函数是最小化 trace(inv(Z'Z)),其中 Z 是通过围绕其参数线性化 ODE 计算的尺度灵敏度矩阵。如您所见,目标函
所以我今天刚尝试使用 LESS。根据官方网站上提供的示例,我已经成功编写了如下所示的 CSS 脚本。但是有一行不能像我想要的那样工作,我想将颜色类型变量转换为字符串(用单引号引起来)。 我有颜色变量,
给定以下形式: 我可以使用 $.param( .. ) 构造来序列化表单: $.param( $('form input') ) => foo=bar&hello=hello+
Python 允许使用 [2,36] 范围内的任何基数将字符串转换为整数: int(string,base) 我正在寻找一个优雅的反函数,它接受一个整数和一个基数并返回一个字符串。 例如: >>> s
我是一名优秀的程序员,十分优秀!