mirror of
https://github.com/kucherenko/jscpd.git
synced 2026-09-19 08:11:03 +08:00
64e471e2b0
Adds 92 new tests (178 → 270 total) with zero source-file modifications: - packages/finder: 13 new test files covering all reporters, subscribers, validators, hooks, utils, options, cloneFound, getFilesToDetect, and InFilesDetector; shared buildClone() factory helper - apps/jscpd: 3 new test files (options-unit, print, store) plus extensions to formats, modes, and options integration tests - vitest.config.ts added to both packages to restrict coverage.include to src/** only, eliminating bin/ and prism.js noise - Fixes 3 tokenizer bugs (trailing space in format lookup, tokenization edge cases) uncovered by the new format fixture suite - Adds fixture files for 40+ language formats to support formats.test.ts
41 lines
1.1 KiB
Mathematica
41 lines
1.1 KiB
Mathematica
(* Wolfram Language - Numerical Analysis *)
|
|
|
|
(* Newton's method for root finding *)
|
|
NewtonRaphson[f_, df_, x0_, opts : OptionsPattern[]] :=
|
|
Module[
|
|
{x = x0, tol = 10^-10, maxIter = 100, iter = 0, history = {}},
|
|
While[
|
|
iter < maxIter,
|
|
AppendTo[history, x];
|
|
x = x - f[x] / df[x];
|
|
iter++;
|
|
If[Abs[f[x]] < tol, Break[]]
|
|
];
|
|
<|"Root" -> x, "Iterations" -> iter, "History" -> history|>
|
|
]
|
|
|
|
(* Secant method - no derivative required *)
|
|
SecantMethod[f_, x0_, x1_, tol_ : 10^-10, maxIter_ : 100] :=
|
|
Module[
|
|
{xPrev = x0, xCurr = x1, xNext, iter = 0},
|
|
While[
|
|
iter < maxIter && Abs[xCurr - xPrev] > tol,
|
|
xNext = xCurr - f[xCurr] * (xCurr - xPrev) / (f[xCurr] - f[xPrev]);
|
|
xPrev = xCurr;
|
|
xCurr = xNext;
|
|
iter++
|
|
];
|
|
<|"Root" -> xCurr, "Iterations" -> iter|>
|
|
]
|
|
|
|
(* Test with x^3 - 2x - 5 = 0 *)
|
|
g[x_] := x^3 - 2 x - 5
|
|
dg[x_] := 3 x^2 - 2
|
|
|
|
nrResult = NewtonRaphson[g, dg, 2.0]
|
|
secResult = SecantMethod[g, 2.0, 3.0]
|
|
|
|
Print["Newton root: ", nrResult["Root"]]
|
|
Print["Secant root: ", secResult["Root"]]
|
|
Print["Agreement: ", Abs[nrResult["Root"] - secResult["Root"]] < 10^-8]
|