小编fba*_*lic的帖子

C#中的N体仿真

我正在尝试使用Runge Kutta 4或Velocity Verlet集成算法在C#中实现N体模拟.

在我移动到更大数量的粒子之前,我想通过模拟围绕太阳的地球轨道来测试模拟,然而,由于某种原因,我得到了一个奇怪的螺旋而不是椭圆轨道.

我无法弄清楚这个问题,因为我使用相同的算法对太阳系进行了简单的模拟,其中太阳被固定在适当的位置并且一切都运行良好.积分器工作得很好,因为我使用哪一个并不重要,我得到两者的螺旋.

任何帮助,将不胜感激.

这是代码:

class NBODY
{
    public static double G = 4 * Math.PI * Math.PI;

    class Particle
    {
        public double[] r;       // position vector
        public double[] v;       // velocity vector
        public double mass;    

        //constructor
        public Particle() {}
        public Particle(double x, double y, double z, double vx, double vy, double vz, double m)
        {
            this.r = new double[3];
            this.v = new double[3];

            this.r[0] = x;
            this.r[1] = y;
            this.r[2] = z;
            this.v[0] = vx;
            this.v[1] …
Run Code Online (Sandbox Code Playgroud)

c# algorithm simulation physics numerical-methods

5
推荐指数
1
解决办法
1235
查看次数

无论我做什么,VSCode Python 版本在集成终端中都默认为 2.7

1.36.0在 MacOS Mojave 10.14.6上运行 VSCode 。

当我在 VSCode 中使用集成终端并运行 Python 时,它始终/usr/bin/python在 MacOS 上运行 Python 2.7,而不是默认的 anaconda Python。如果我在系统终端中做同样的事情,一切都很好。

我看过这两个相关问题的答案:

为什么 macOS Visual Studio Code 使用错误的 Python 解释器?

如何在 Visual Studio Code 中更改 python 版本?

我没有运行代码运行器扩展。我已将python.pythonPath设置更新为指向 Anaconda Python,但无论我做什么,which python在集成终端中都会返回/usr/bin/python. 选择不同的 conda 环境conda activate myenv也没有任何作用。

以前没有遇到过这个问题。

python visual-studio-code vscode-settings

4
推荐指数
1
解决办法
1004
查看次数

通过 pybind11 迭代用 Python 包装的 C++ 对象

我有定义一个curves类、一个curve类和一个point类的C++ 代码,我正在尝试通过 pybind11 为这些类编写 Python 绑定并在 Python 中使用它们。

这些类的 pybind11 绑定如下所示:

namespace py = pybind11;

PYBIND11_MODULE(mymodule, m) {
    py::class_<_point>(m, "_point")
        .def(py::init<double, double>()) 
        .def_readwrite("next", &point::next)
        .def_readwrite("prev", &point::prev)
        .def_readonly("x1", &point::x1)
        .def_readonly("x2", &point::x2);
    py::class_<curve>(m, "curve")
        .def(py::init<point*>()) //constructor 1
        .def(py::init()) //constructor 2
        .def_readwrite("first", &curve::first)
        .def_readwrite("last", &curve::last)
        .def_readwrite("next", &curve::next)
        .def_readwrite("prev", &curve::prev);
    py::class_<curves>(m, "curves")
        .def(py::init()) 
        .def_readwrite("first", &curves::first)
        .def_readwrite("last", &curves::last);
}
Run Code Online (Sandbox Code Playgroud)

在 C++ 中,我可以通过以下方式遍历一个由curves对象curve 组成的point对象:

for(curve *c=curves_pointer->first; c; c=c->next) {
      for(point *p=c->first; p; p=p->next) {
          cout …
Run Code Online (Sandbox Code Playgroud)

c++ python pointers pybind11

1
推荐指数
1
解决办法
2177
查看次数