{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#A helpful script for Exercise 3.4.9, modeling a cooling potato.\n", "\n", "#The data, in time/temperature pairs:\n", "data = [[0, 204], [2, 193], [4, 184], [8, 169], [10, 162], [13, 156], [17, 149], [20, 143], [24, 138], [30, 130]]\n", "N = len(data);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#A plot:\n", "plt1 = scatter_plot(data);\n", "show(plt1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#The temperature might be modeled by the function\n", "var('t k');\n", "u(t,k) = 72 + 132*exp(-k*t); #The model function to fit\n", "SS = function('SS')(k);\n", "SS(k) = add((u(data[i][0],k)-data[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 }