### Pass function returning value and derivative to root-1d

parent 5be849e0
 ;; Minimize or maximize the function in one variable. ;; Liam Healy 2011-01-14 12:18:15EST minimize.lisp ;; Time-stamp: <2015-11-22 11:43:17EST one-dim.lisp> ;; Time-stamp: <2017-09-21 18:23:03CDT one-dim.lisp> ;; Copyright 2011, 2014, 2015 Liam M. Healy ;; Copyright 2011, 2014, 2015, 2017 Liam M. Healy ;; Distributed under the terms of the GNU General Public License ;; ;; This program is free software: you can redistribute it and/or modify ... ... @@ -26,13 +26,21 @@ (defgeneric root-1d (function initial derivative &optional absolute-error relative-error method) (:documentation "Find the root of a real function of a real variable. Returns the argument value of the root and the computed value of the function at that value. The argument and return values may be physical quantities.") "Find the root of a real function of a real variable. Returns the argument value of the root and the computed value of the function at that value. The argument and return values may be physical quantities. If derivative is nil, the function should return value and derivative as multiple values.") (:method (function (initial t) derivative &optional absolute-error relative-error method) (let ((solver (gsl:make-one-dimensional-root-solver-fdf method function derivative (lambda (x) (values (funcall function x) (funcall derivative x))) initial))) (let ((solver (if derivative (gsl:make-one-dimensional-root-solver-fdf method function derivative (lambda (x) (values (funcall function x) (funcall derivative x))) initial) ;; Function returns two values, the value and the derivative. (gsl:make-one-dimensional-root-solver-fdf method function (lambda (&rest args) (nth-value 1 (apply function args))) function initial)))) (iter (iter:for oldroot first initial then root) (gsl:iterate solver) (iter:for root = (gsl:solution solver)) ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!