{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#A helpful script for Exercise 3.4.1.\n", "\n", "#Here is the data for Exercise 3.4.1\n", "data = [[0.1, 0.11], [0.6, 0.5], [1.1, 0.6], [1.4, 0.5]];\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": [ "#aTo fit a function u(a,t) = a*t to this data by adjusting \"a\", define\n", "var('t a');\n", "u(t,a) = a*t; #The model function to fit\n", "SS = function('SS')(a);\n", "SS(a) = add((u(data[i][0],a)-data[i][1])^2 for i in range(N));" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Now minimize SS(a) with respect to a. Repeat for parts (b)-(d)." ] } ], "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 }