用浏览器内JS数值求解三角函数方程 [英] solving a trig equation numerically with in-browser JS

查看:155
本文介绍了用浏览器内JS数值求解三角函数方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出变量svh的值,并给出一个库,例如以下方程式在给定的准确度范围内a?

Given values for the variables s, v, and h, and given a library such as numeric.js how can I numerically solve the following equation for a within a given degree of accuracy?

我想要在浏览器中使用JS算法.

I'm wanting a JS algorithm for use in-browser.

推荐答案

分隔变量和参数

您可以先替换b = a/h.那会让你的方程变成

Separating variables and parameters

You could start by substituting b = a/h. That would turn your equation into

2b * sinh(1/(2b))= sqrt(s²-v²)/h

2b*sinh(1/(2b)) = sqrt(s²-v²)/h

这样,您的所有输入都在右侧,而变量在左侧,但不幸的是,它仍然以先验的形式出现在多个地方.好处是我们现在可以将右侧视为一个数字,以便对该功能有所了解.

That way you have all the inputs on the right hand side, and the variable on the left hand side, but unfortunately still occuring in several places in a transcendental form. The benefit is that we can now treat the right-hand side as a single number in order to gain some understanding of this function.

该功能似乎表现良好:

因此,您可以标准数值根查找方法,例如牛顿方法,以查找此函数采用给定值(即一个)的位置您是从右侧计算的).如果您将查找根目录解释为查找某个函数为零的位置,那么您要为其查找零的函数就是其差值,即

So you can do standard numerical root-finding methods, e.g. Newton's method, to find the position where this function takes a given value (i.e. the one you computed from the right-hand side). If you interpret root-finding as finding locations where a function is zero, then the function for which you want to find zeros is the difference, i.e.

2a * sinh(h/(2a))-sqrt(s²-v²)

2a*sinh(h/(2a)) - sqrt(s²-v²)

使用numeric.js中的优化

如果您要使用 numeric.js ,则numeric.uncmin可能是你最好的选择.至少这是迄今为止我在文档中可以找到的最好的. (也许那里有一些根本的查找根的实现,但是如果是这样,我还找不到它.)您将尝试找到该函数的最小值

Using optimization from numeric.js

If you want to make use of numeric.js, numeric.uncmin would likely be your best bet. At least it's the best I could find in the docs so far. (Perhaps there is some bare root-finding implementation in there, but if so, I couldn't find it yet.) You'd try to find the minimum of the function

(2a * sinh(h/(2a))-sqrt(s²-v²))²

(2a*sinh(h/(2a)) - sqrt(s²-v²))²

解释为a的函数,并希望该最小值实际为(接近)零.您还可以通过将该函数的梯度(导数)作为单独的参数来提供更好的结果(即更快的收敛速度和/或更低的误差).您可以

interpreted as a function of a, and hope that that minimum is actually (close to) zero. You might get better results (i.e. faster convergence and/or lower error) by also providing the gradient (derivative) of that function as a separate argument. You can use Wolfram Alpha to find that derivative.

让我们将f定义为f(b)= 2b * sinh(1/(2b)).您试图找出f处于给定值的位置.为了使收敛更快,您可以尝试将此f转换为接近线性的其他函数.玩弄情节,我想出了这个:

Let's define f as f(b) = 2b*sinh(1/(2b)). You are trying to find out at what position f assumes a given value. In order to make convergence faster, you can try to turn this f into a different function which will be close to linear. Toying around with plots, I've come up with this:

g(b)=(f(b)-1)^(-1/2)

g(b) = (f(b) - 1)^(-1/2)

您可以在右侧应用相同的转换,以查看该功能所需的值.对于b   0.06来说,它看起来是线性的,因此应该非常快地收敛.只要您的参数期望在几乎是线性的范围内,但是即使对于较小的 b ,它也应不比原始公式差.您可以使用线性形式来计算牛顿方法的起始位置,但我不会打扰:只要您从一个相当大的值开始,牛顿方法的第一步就可以做到这一点.

You can apply the same conversion to the right hand side to see the desired value for this function. For b > 0.06 this looks fairly linear, so it should converge really fast. Provided your parameters are expected to be in that range where it is almost linear, but even for smaller b it should be no worse than the original formulation. You could use the linear form to compute the starting position of your Newton's method, but I wouldn't bother: as long as you start with a reasonably big value, the first step of Newton's method will do just that.

这篇关于用浏览器内JS数值求解三角函数方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆