COSC 311 Information on Sage -- curve fitting sagemath.org: Online version and downloadable version http://doc.sagemath.org/html/en/tutorial/index.html: Sage tutorial ***************************************************************************** Documentation/examples for curve fitting (find_fit): http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html: --------------------------------------------------------------------------- initialize variable with data values: data=[ (10, 100), (20, 205), (30, 199), (40, 400), (50, 500), (60, 600) ] --------------------------------------------------------------------------- create variables for use in fitting: var('a, b, c, x') --------------------------------------------------------------------------- create models (function) to use for fitting lin_model(x) = a * x + b quad_model(x) = a * x^2 + b * x + c log_model(x) = a * x * log(x) + b * x + c --------------------------------------------------------------------------- find best fit find_fit(data, lin_model) *************************************************************************** Documentation/examples for plotting: http://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html#sage.plot.plot.plot --------------------------------------------------------------------------- plot one of the curves: plot(10.24*x - 24.6, 0, 600, color='red') --------------------------------------------------------------------------- Add to plot: P = plot(10.24*x - 24.6, 0, 600, color='red') P = P + plot(.071 * x^2 + 5.26 * x + 41.9, 0, 600, color='black') P --------------------------------------------------------------------------- plot data points: list_plot( data, color='blue' ) --------------------------------------------------------------------------- Draw points and fitted curves: P = list_plot( data, color='blue' ) P += plot(.071 * x^2 + 5.26 * x + 41.9, 0, 60, color='black') P += plot(10.24*x - 24.6, 0, 60, color='red') P