Previous Up Next

8.2.6  Logarithmic regression: logarithmic_regression logarithmic_regression_plot

A set of points might be expected to lie on a logarithmic curve y=m ln(x) + b. Given a set of points, either as a list of x-coordinates followed by a list of y-coordinates, or simply by a list of points, the logarithmic_regression command will find the values of m and b which give the best fit exponential. For example, if you enter

evalf(logarithmic_regression([[1,1],[2,4],[3,9],[4,16]]))

or

evalf(logarithmic_regression([1,2,3,4],[1,4,9,16]))

(where the evalf is used to get a numeric approximation to an exact expression) you will get

10.1506450002,-0.564824055818

so the best fit exponential curve will be y = 10.1506450002 ln(x) −0.564824055818.

To plot the curve, you can use the command exponential_regression_plot; if you enter

logarithmic_regression_plot([1,2,3,4],[1,4,9,16])

you will get

which plots the graph, and has the equation and R2 value above the graph.


Previous Up Next