问题标签 [numerics]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
179 浏览

python - Plot Surface instead of parametric curve

I am working on using the forward difference scheme for numerically solving the diffusion function in one dimension. My final plot of the solution should be a surface where the solution u(x,t) is plotted over a grid of x and t values. I have the problem solved, but I can't get the data to be plotted with the grid representation.

I can think of 2 ways to fix this:

1.) My x and t arrays should be one dimensional, but my u array should be a 2D array. Ultimately, I want a square matrix for u, but I am having a hard time coding that. Currently I have a 1D array for u. Here is the code where u is populated.

2.) The above code returns a 1D array for u, is there a way to plot a 3D surface with 3 1D arrays for x,y,z?

0 投票
3 回答
2869 浏览

python - Python中比较数字的一般方法

我一直在寻找一种在 Python 中比较两个数字的通用方法。特别是,我想弄清楚它们是否相同。

Python 中的数值类型有:

例如,我可以通过简单地说来比较 2 个整数(一种数字):

对于浮点数,由于舍入精度,我们必须更加小心,但我可以在一定的公差范围内比较它们。

问题

我们得到 2 个通用数字ab: 我们如何比较它们?我正在考虑将两者都转换为复杂的(如果类型是 0,那么它的虚部是 0 int)并在该域中进行比较?

这个问题比简单地直接比较浮点数更笼统。当然和这个问题有关,但又不一样。

0 投票
1 回答
2428 浏览

c# - 使用 System.Numerics 进行矩阵乘法的值完全错误

尽管System.Numerics.Vectors可以通过 NuGet 获得的库有自己的视图和投影矩阵函数,但我想自己实现它,只使用向量和矩阵结构。

不幸的是,当我的目标向量与(正确的)视图矩阵相乘时,我已经得到了一个完全错误的结果。我正在使用右手坐标系和以下说明

具有以下功能

在我上面的示例中,预期的视图矩阵是

并且vMatrix4确实具有相同的价值。然而,乘以vMatrix4应该targetVector4产生<1, 0.894427, -4.91935, 1>但 Visual Studio 报告<1, -0.8944272, -0.4472136, 5.472136>

我的问题是,库在计算结果时是否存在数值问题,是否存在数据类型不匹配或者我是否使用Vector4.Transform错误地期望它返回ViewMatrix * TargetVector


编辑

使用以下自定义扩展方法时

调用targetVector4.ApplyMatrix(targetVector4)产生正确的结果。这意味着内部Vector4.Transform似乎做了一些非常出乎意料的事情。

0 投票
2 回答
622 浏览

exception - MathNet 数值 - 傅里叶 - “不支持指定的方法”

我有一个 C# 应用程序,我通过 Nuget 安装了 MathNet.Numerics 3.17.0。

我正在尝试使用傅立叶函数。当我运行这行代码时:

它抛出异常“不支持指定的方法”。

返回“托管”。

我发誓这是有效的,但现在它坏了。

关于如何使这项工作的任何想法?

仅供参考,我正在使用 MKL 包一分钟,这似乎有效。我想使用本机包“托管”,因为我通过 clickonce 分发应用程序....

任何想法表示赞赏!

0 投票
0 回答
38 浏览

numerics - Converting decimal number to IEEE format

Hello stackoverflow community, Today I want to know if my solution for this question is correct or not , and if it is not please tell me why and what is the correctness of it and thanks in advance.

The question : Convert the decimal number 1.5 x 2^-126 to IEEE single-precision format.

My answer is : 00000000110000000000000000000000 , where :-

*sign-bit = 0 (positive floating point number)

*Exponent = -126+Bias = -126+127=+1 = 00000001

*Mantissa bits = 10000000000000000000000 (1.5 in decimal = 1.1 in normalized binary form)

0 投票
0 回答
68 浏览

astronomy - Using Newton-Raphson method to solve the hydrostatic equation

I'm trying to use newton-raphson method for nonlinear systems of equations as discribed in 'Numerical recipies' book in chapter 9.6 to solve the hydrostatic equetion for a polytropic star.

For each iteration, I change the radius vector as discribed in the book like x-> x+delta (delta can be calculated for each iteration) but I can't ignore the fact that it can do shell crossing - meaning the i shell moves to a higer shell then i+1 , this cause a negative volume. I know there is a method to avoid shell crossing by multiplying delta with a factor but I don't know how to calculate it. There is no description in the book about shell crossing.

Do anyone know how to help? thank's

0 投票
1 回答
238 浏览

scala - 使用数值泛型的 Scala 操作

当我试图做

在 Scala 2.12 中,-无法识别。但是,这基本上等同于 Scala 中带有泛型类型参数的 Addition所建议的。我需要改变什么?

0 投票
2 回答
3270 浏览

algorithm - 浮点数的二进制搜索/二分法

用二分查找很容易找到一个整数,即使它可以是任意大的:首先猜测数量级,然后继续划分区间。 该答案描述了如何找到任意有理数。

设置好场景后,我的问题类似:我们如何猜测 IEEE 754 浮点数?假设它不是 NaN,但其他一切都是公平的游戏。对于每个猜测,您的程序将被告知所讨论的数字是更高、相等还是更低。最小化最坏情况下所需的猜测次数。

(这不是家庭作业。不过,我可能会做一个,如果结果证明这是一个有趣的答案,而不仅仅是“通过大量特殊情况处理将浮点数值困难打死。”)

编辑:如果我在搜索方面做得更好,我可以找到答案--- 但只有当你已经知道重新解释是int有效的(有某些警告)时才有效。所以留下这个。感谢哈罗德的精彩回答!

0 投票
1 回答
33 浏览

sql - 检查字母和数字

我正在使用 dbvisualizer SQL 语句,并试图搜索一个字段是否有字母和数字,或者只有一个或另一个。这可以以简单的方式完成吗?目前我只是像这样单独检查每一个:

0 投票
2 回答
62 浏览

dictionary - 通用操作字典的问题

我有一本操作字典:

使用辅助功能:

然后我们有一个使用 MailboxProcessor 代理的简单计算器:

作为一个使用示例,我们有:

问题是 Add and Multiply 和 Last Divide 工作正常:

一旦我们使用 Subtract 和 first Divide int option = None,我就会遇到麻烦,以下是我从任何操作中得到的唯一输出:

只要我仔细考虑,我无法弄清楚“减”/“除”部分或“接收”/“回复”操作是否有问题。