{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#A helpful script for Exercise 3.4.2.\n", "\n", "#Here is the data for Exercise 3.4.2\n", "data = [[0, 1.0], [300, 0.78], [1200, 0.37], [3000, 0.08]];\n", "N = len(data);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#However, we will work with the log of the concentration, so form\n", "logdata = [[data[i][0],log(data[i][1])] for i in range(N)];" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#A plot:\n", "plt1 = scatter_plot(logdata);\n", "show(plt1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#aTo fit a function u(k,t) = k*t to this data by adjusting \"k\", define\n", "var('t k');\n", "u(t,k) = k*t; #The model function to fit\n", "SS = function('SS')(k);\n", "SS(k) = add((u(logdata[i][0],k)-logdata[i][1])^2 for i in range(N));" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Now minimize SS(k) with respect to k." ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.2", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }