Skip to content

MyMath.Sin()が壊れている #234

Closed

Description

@iwkjosec

[構造化] 名前空間 エイリアス

Console.Write("{0:f2},           {1:f6},            {1:f6}\n", x, y, z);

出力がx y yになっています
これを直すと

Console.Write("{0:f2},           {1:f6},            {2:f6}\n", x, y, z);

実行結果はこうなります。

   x, System.Math.Sin(x), Ufcpp.Math.Sin(x)
0.00,           0.000000,            NaN
0.01,           0.010000,            NaN
0.02,           0.019999,            NaN
0.03,           0.029996,            NaN
0.04,           0.039989,            NaN
0.05,           0.049979,            NaN
0.06,           0.059964,            NaN
0.07,           0.069943,            NaN
0.08,           0.079915,            NaN
0.09,           0.089879,            NaN

自作のSin()が壊れています

マクローリン展開ですよね
ループ変数のiが0ではなく2で始まっていればよく、++iが一つ余計だから
for(int i=0; i<100; ++i) -> for(int i=2; i<100;)
これで実行結果は

   x, System.Math.Sin(x), Ufcpp.Math.Sin(x)
0.00,           0.000000,            0.000000
0.01,           0.010000,            0.010000
0.02,           0.019999,            0.019999
0.03,           0.029996,            0.029996
0.04,           0.039989,            0.039989
0.05,           0.049979,            0.049979
0.06,           0.059964,            0.059964
0.07,           0.069943,            0.069943
0.08,           0.079915,            0.079915
0.09,           0.089879,            0.089879

となります。(結局変わってない)

マクローリン展開を50項目ぐらいまで計算しているのでかなりの精度が出ていて
小さい値なら15桁
±25ぐらいでも5桁ほど

Activity

  1. iwkjosec commented on Mar 14, 2019

    @iwkjosec
    Author

    [オブジェクト指向] 静的メンバー
    このページに2か所同じSinメソッドがあってpublicが足りなくてコンパイルエラーに
    2つめのほうは外部から呼ぶコードはセットになってないけどたぶんpublicを意図しているはず。

    2つめのほうの名前がMyMathじゃなくてMathなのは誤植なんですかね?

  2. ufcpp commented on Apr 20, 2019

    @ufcpp
    Owner

    修正。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions