Commit 155af5c9 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Documenation updates, fix for iteration defclause package

parent 2b6faf80
;; Find the Jacobian matrix of a multivariate function
;; Liam Healy 2011-10-15 12:40:05EDT jacobian.lisp
;; Time-stamp: <2013-12-25 19:09:57EST jacobian.lisp>
;; Time-stamp: <2015-11-21 15:06:38EST jacobian.lisp>
;; Copyright 2011, 2013 Liam M. Healy
;; Copyright 2011, 2013, 2015 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
......@@ -21,25 +21,29 @@
;;; This does not use GSLL's central-difference, because that is scalar only and it would be inefficient to repeatedly re-evaluate the function to get the various components.
(in-package :antik)
(export 'jacobian-matrix)
(defun jacobian-matrix
(function point step
&optional (matrix-or-nrows (grid:dim0 (funcall function point))))
"The matrix of partial derivatives of the function. If the number
of rows nrows is not supplied, it is determined by evaluating the
function at the point; supplying this information avoids that
calculation. Step must be a scalar."
"The matrix of partial derivatives of the function. If the number of rows nrows is not supplied, it is determined by evaluating the function at the point; supplying this information avoids that calculation. Step must be a scalar."
;; This cannot currently use pq.
(let ((matrix (if (grid:gridp matrix-or-nrows)
matrix-or-nrows
(grid:make-simple-grid
:dimensions (list (grid:dim0 point) matrix-or-nrows)
:grid-type (grid:gridp point)))))
(iter (for col from 0 below (grid:dim1 matrix))
(let ((pos (grid:copy point :grid-type *default-grid-type*))
(neg (grid:copy point :grid-type *default-grid-type*)))
(iter (iter:for col from 0 below (grid:dim1 matrix))
(let ((pos (grid:copy point :grid-type grid:*default-grid-type*))
(neg (grid:copy point :grid-type grid:*default-grid-type*)))
(incf (grid:aref pos col) (/ step 2))
(decf (grid:aref neg col) (/ step 2))
(iter:for column = (/ (- (funcall function pos) (funcall function neg)) step))
(unless matrix
(setf matrix
(grid:make-simple-grid
:dimensions (list (grid:dim0 point) (grid:dim0 column))
:grid-type (grid:gridp point))))
(setf (grid:column matrix col)
(/ (- (funcall function pos) (funcall function neg)) step))))
)))
matrix))
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 0583f5cb403f591c8a4eb836577b4484
config: bc74e20fb1c456a2641a76bf1dd5b6ee
tags: 645f666f9bcd5a90fca523b33c5a78b7
Conditions
==========
Conditions helpful for arithmetic calculations are provided. Complex number are sometimes undesirable; ``making-complex-number`` is a condition that will be signalled when a computation will produce a complex number. The macro ``handling-complex-number`` allows various restarts which can be selected, depending on the desired action. For example::
(handling-complex-number return-zero
(/ (sin x)
(* pi (sqrt (+ (expt (cos y) 2)
(expt (* (cos z) (sin y)) 2)
(- (expt (cos x) 2)))))))
will return zero if from the body form if any calculation inside returns a complex number.
.. cl:package:: antik
.. FAIL cl:condition:: coerce-undefined
.. FAIL cl:condition:: coerce-nil
.. FAIL cl:condition:: making-complex-number
.. cl:macro:: handling-complex-number
.. cl:macro:: arithmetic-errors-return-nan
Elementary Mathematical Functions
====================
=================================
Generic mathematical functions are provided so that they may be called on something other than numbers, such as grids. When called with CL numbers, they call the equivalent CL function.
.. cl:package:: antik
.. cl:function:: abs
.. cl:function:: acos
.. cl:function:: asin
.. cl:function:: atan
.. cl:function:: cosh
.. cl:function:: cos
.. cl:function:: exp
.. cl:function:: expt
.. cl:function:: floor
.. cl:function:: round
.. cl:function:: signum
.. cl:function:: sinh
.. cl:function:: sin
.. cl:function:: sqrt
.. cl:function:: tanh
.. cl:function:: tan
.. cl:function:: =
.. cl:function:: >=
.. cl:function:: >
......@@ -32,5 +23,3 @@ Generic mathematical functions are provided so that they may be called on someth
.. cl:function:: -
.. cl:function:: *
.. cl:function:: /
......@@ -3,7 +3,7 @@ Introduction to Antik
Antik provides a foundation for scientific and engineering computation in Common Lisp. It is designed not only to facilitate numerical computations, but to permit the use of numerical computation libraries and the interchange of data and procedures, whether foreign (non-Lisp) or Lisp libraries. Notably, GSLL_ provides an interface to the GNU Scientific Library (GSL_) and is based on Antik.
Antik is designed and developed to provide a common foundation and interoperability between scientific, engineering and mathematical libraries, whether in Lisp or not. Interoperability means that objects created can easily be passed to one or more libraries, and libraries can be mixed and combined to solve a problem. It also means that names of like functions will be the same, differening only in the package. For example, if systems ``foo`` and ``bar`` both provide an LU decomposition, that function will be ``foo:lu-decomposition`` in one and ``bar:lu-decomposition`` in the other. Should a user wish to compare or switch libraries in such a function call, it is a simple matter of changing the package. If a whole library should be switched, the names can be used without a package prefix and the use-package form changed. This makes it easy to compare results, and select and mix the best libraries for a calculation.
Antik is designed and developed to provide a common foundation and interoperability between scientific, engineering and mathematical libraries, whether in Lisp or not. Interoperability means that objects created can easily be passed to one or more libraries, and libraries can be mixed and combined to solve a problem. It also means that names of like functions will be the same, differing only in the package. For example, if systems ``foo`` and ``bar`` both provide an LU decomposition, that function will be ``foo:lu-decomposition`` in one and ``bar:lu-decomposition`` in the other. Should a user wish to compare or switch libraries in such a function call, it is a simple matter of changing the package. If a whole library should be switched, the names can be used without a package prefix and the use-package form changed. This makes it easy to compare results, and select and mix the best libraries for a calculation.
.. _GSLL: http://common-lisp.net/project/gsll/
.. _GSL: http://www.gnu.org/software/gsl/
Linear Agebra
=============
At present, these call the LU methods in GSLL. Someday, they will take arguments to allow other methods and libraries. To find the inverse and determinant of a matrix, use ``invert-matrix`` with a two-dimensional ``foreign-array``::
> (invert-matrix
(grid:make-foreign-array
'double-float :initial-contents '((1.0d0 2.0d0) (3.0d0 4.0d0))))
#m((-2.000000000000000d0 1.000000000000000d0)
(1.500000000000000d0 -0.500000000000000d0))
-2.0
.. cl:package:: antik
.. cl:function:: invert-matrix
.. cl:function:: determinant
.. cl:function:: solve-linear
Mathematics
=================================
Contents:
.. toctree::
:maxdepth: 2
elemmath
trigonometry
optimize
linalg
statistics
Optimization
============
.. cl:package:: antik
.. cl:function:: root-1d
.. cl:function:: minimize-1d
.. cl:function:: maximize-1d
.. cl:function:: linear-least-squares-1d
......@@ -14,8 +14,9 @@ Contents:
intro
starting
packages
elemmath
mathematics
utility
conditions
Indices and tables
==================
......
Statistics
==========
Given a function ``#'make-orbit`` which takes several keyword arguments ``:semimajor-axis``, ``:eccentricity`` and ``:inclination``, the is example of ``low-discrepancy-sample`` will make five orbits with values in the specified ranges::
(low-discrepancy-sample
5
'make-orbit
'(:semimajor-axis #_7000_km #_9000_km)
'(:eccentricity 0.0)
'(:inclination #_95_deg #_105_deg))
.. cl:package:: antik
.. cl:function:: low-discrepancy-sample
.. cl:function:: apply-to-arguments
.. cl:function:: list-no-key
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment