标签: newtons-method

Matlab中的Newton Raphsons方法?

Newtons-Raphsons方法很容易在Mathematica中实现,但在Matlab中似乎有点困难.如果我可以将函数传递给函数以及如何将派生函数用作函数,我不会得到.

newtonRaphson[f_, n_, guess_] := 
 If[n == 0, guess, newtonRaphson[f, n - 1, guess - f[guess]/f'[guess]]]
newtonRaphsonOptimize[f_, n_, guess_] := 
 If[n == 0, guess, 
  newtonRaphsonOptimize[f, n - 1, guess - f'[guess]/f''[guess]]]
Run Code Online (Sandbox Code Playgroud)

似乎你既不能导出函数句柄也不能导出文件中定义的函数,但我可能错了.

matlab newtons-method

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

ZeroDivisionError:浮点除法

我有这个代码来解决牛顿的方法.但它给出了零分割错误.我无法弄清楚出了什么问题.谢谢.

import copy

tlist = [0.0, 0.12, 0.16, 0.2, 0.31, 0.34] # list of start time for the phonemes

w = w1 = w2 = w3 = w = 5

def time() :
    frame = 0.04
    for i, start_time in enumerate(tlist) :
        end_time = tlist[i]
        frame = frame * (i + 1)
        poly = poly_coeff(start_time, end_time, frame)
        Newton(poly) 

def poly_coeff(stime, etime, f) :
    """The equation is k6 * u^3 + k5 * u^2 + k4 * u + k0 = …
Run Code Online (Sandbox Code Playgroud)

python newtons-method

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

二分法(数值分析)

在找到每个单根之前会进行多少次递归?还有,哪些是根?


这是我的代码:

e=0.000001; 
f1=@(x) 14.*x.*exp(x-2)-12.*exp(x-2)-7.*x.^3+20.*x.^2-26.*x+12;

a=0; 
c=3; 
while abs(c-a)>e 
    b=(c+a)/2; 
    if f1(a)*f1(b)<0 
        c=b; 
    else
        a=b;
    end    
    disp(b);  
end
Run Code Online (Sandbox Code Playgroud)

matlab numerical analysis newtons-method bisection

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

为什么在计算1.0E21和1.0E23的平方根时Newton-Raphson方法不会收敛?

我有以下函数用于使用Newton-Raphson方法计算数字的平方根.

double get_dx(double y, double x)
{
   return (x*x - y)/(2*x);
}

double my_sqrt(double y, double initial)
{
   double tolerance = 1.0E-6;
   double x = initial;
   double dx;
   int iteration_count = 0;
   while ( iteration_count < 100 &&
           fabs(dx = get_dx(y, x)) > tolerance )
   {
      x -= dx;
      ++iteration_count;
      if ( iteration_count > 90 )
      {
         printf("Iteration number: %d, dx: %lf\n", iteration_count, dx);
      }
   }

   if ( iteration_count < 100 )
   {
      printf("Got the result to converge in %d …
Run Code Online (Sandbox Code Playgroud)

c algorithm newtons-method

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

关于麻省理工学院6.00课程lec06 - 牛顿的方法

我试图以自己的方式编码,但发现我得到了错误的答案.

我看过这个页面.并尝试启动该过程:

在此输入图像描述

F(X)= X ^ 2-E

数学:

在此输入图像描述

所以有我的代码:

def sqrtRootNR(num, count, epsl):
    """
    for test
    """
    num = float(num)
    guess = num / 2.0
    diff = guess ** 2.0 - num
    _cnt = 0
    while abs(diff) > epsl and _cnt < count:
        guess = guess - (guess ** 2.0 + epsl) / (guess * 2.0)
        diff = guess ** 2.0 - num
        _cnt = _cnt +1
    print guess, _cnt

sqrtRootNR(2, 100, 0.0001)
Run Code Online (Sandbox Code Playgroud)

但是,我得到了错误的答案.

该函数的输出是:

D:\ poc> python sq.py …

python math newtons-method

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

行星轨道的数值逼近

新的一天新的问题...

我按照埃里克(Eric)所说的做,并为Acceleration创建了一种方法!

看起来像这样:

static Vector2 AccelerationOfTheMoon(Vector2 position)
    {
        double Mm = 7.349 * Math.Pow(10, 22);

        double MagnitudeOfForce()
        {
            double MagF = position.LengthSquared();
            return MagF;
        }

        Vector2 ForceAsVector()
        {
            return position.NegativeUnitVector() * MagnitudeOfForce();
        }

        Vector2 acceleration = ForceAsVector() / Mm;


    }
Run Code Online (Sandbox Code Playgroud)

以我的方式看,我的名为AccelerationOfTheMoon的方法会收到带有位置的向量2。现在,我想使用此向量,因此我创建了另一个方法,该方法应将我的Magnitude作为标量(双精度)返回。为此,我创建了一种方法来计算向量的幅度并将其平方。当我在ForceAsVector-Method中调用MagnitudeOfForce-Method时,我正在尝试将负单位矢量与标量相乘,并将其作为Vector2返回。

也许我在这里做得很糟糕,但是我正在努力了解Eric所做的一切,仍然需要您的帮助!

谢谢。

c# vector newtons-method numerical-methods orbital-mechanics

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

这个C成语是什么意思?

可能重复:
约翰卡马克不寻常的快速反向平方根(Quake III)

我最近在博客上看到了这段代码 - 它来自Quake3引擎.它意味着使用Newton-Rhapson方法快速计算平方根.

float InvSqrt (float x){
    float xhalf = 0.5f*x;
    int i = *(int*)&x;
    i = 0x5f3759df - (i>>1);
    x = *(float*)&i;
    x = x*(1.5f - xhalf*x*x);
    return x;
}
Run Code Online (Sandbox Code Playgroud)

这样做的原因是什么int i = *(int*)&x;?这样做int i = (int) x;,而不是给出一个完全不同的结果.

c math floating-point newtons-method

-1
推荐指数
2
解决办法
604
查看次数