diff options
author | Karl Berry <karl@freefriends.org> | 2016-04-07 16:52:56 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-04-07 16:52:56 +0000 |
commit | e1e1d6fa3224440612d3ad6595c413f88d552702 (patch) | |
tree | eaa3301c9fecd1d01baa642b2e483fee4430bcee /Master/texmf-dist/asymptote/math.asy | |
parent | 0eefec13710bb4d6aff6838a6efc463912506ee9 (diff) |
asymptote 2.37
git-svn-id: svn://tug.org/texlive/trunk@40303 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/asymptote/math.asy')
-rw-r--r-- | Master/texmf-dist/asymptote/math.asy | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Master/texmf-dist/asymptote/math.asy b/Master/texmf-dist/asymptote/math.asy index 47044a75df1..9d10e2b7794 100644 --- a/Master/texmf-dist/asymptote/math.asy +++ b/Master/texmf-dist/asymptote/math.asy @@ -423,3 +423,29 @@ pair[][] fft(pair[][] a, int sign=1) } return transpose(A); } + +// Given a matrix A with independent columns, return +// the unique vector y minimizing |Ay - b|^2 (the L2 norm). +// If the columns of A are not linearly independent, +// throw an error (if warn == true) or return an empty array +// (if warn == false). +real[] leastsquares(real[][] A, real[] b, bool warn=true) +{ + real[] solution=solve(AtA(A),b*A,warn=false); + if (solution.length == 0 && warn) + abort("Cannot compute least-squares approximation for " + + "a matrix with linearly dependent columns."); + return solution; +} + +// Namespace +struct rootfinder_settings { + static real roottolerance = 1e-4; +} + +real findroot(real f(real), real a, real b, + real tolerance=rootfinder_settings.roottolerance, + real fa=f(a), real fb=f(b)) +{ + return _findroot(f,a,b,tolerance,fa,fb); +} |