From 6c1d7ceb164445b76b37db565ed100957dcc7382 Mon Sep 17 00:00:00 2001 From: ande2472 <ande2472@msu.edu> Date: Tue, 28 Jun 2022 03:14:40 -0400 Subject: [PATCH] Upload New File --- Gradients.ipynb | 226 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 Gradients.ipynb diff --git a/Gradients.ipynb b/Gradients.ipynb new file mode 100644 index 0000000..ba4c1de --- /dev/null +++ b/Gradients.ipynb @@ -0,0 +1,226 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 32, + "id": "fc73d74c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('answercheck.py', <http.client.HTTPMessage at 0x7fc9a8612220>)" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "##ANSWER##\n", + "#Install answercheck in current director\n", + "from urllib.request import urlretrieve\n", + "urlretrieve('https://raw.githubusercontent.com/colbrydi/jupytercheck/master/answercheck.py', filename='answercheck.py')\n", + "##ANSWER##" + ] + }, + { + "cell_type": "markdown", + "id": "3c2a4f39", + "metadata": {}, + "source": [ + "# Gradients\n", + "Pandas is a python library used to analyze data." + ] + }, + { + "cell_type": "markdown", + "id": "71e867d9", + "metadata": {}, + "source": [ + "## Learning Goal\n", + "To _**understand**_ how to take a multivariable/partial derivative.\n" + ] + }, + { + "cell_type": "markdown", + "id": "5d237ca9", + "metadata": {}, + "source": [ + "## Training Materials\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "21f9b14e", + "metadata": {}, + "source": [ + "For a general understanding of gradients, check out the following website:\n", + "\n", + "https://www.khanacademy.org/math/multivariable-calculus/multivariable-derivatives/partial-derivative-and-gradient-articles/a/the-gradient#:~:text=In%20the%20case%20of%20scalar,partial%20derivatives%20into%20a%20vector.\n" + ] + }, + { + "cell_type": "markdown", + "id": "1e57b578", + "metadata": {}, + "source": [ + "## Self Assessment\n" + ] + }, + { + "cell_type": "markdown", + "id": "1b047470", + "metadata": {}, + "source": [ + "✅ **<span style=\"color:red\">Question:</span>** Find (how do I make a $\\nabla$f for the following equations:\n", + "\n", + "\n", + "1. $f(x, y) = x^3 - y^2$\n", + "2. $f(x,y) = xy^2 + 2x^4y$\n", + "3. $f(x,y) = cos(xy) - xsin(y)$\n", + "4. $f(x,y,z) = z^3 + (x/y) - 2xz$\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3b8e33ef", + "metadata": {}, + "outputs": [], + "source": [ + "#Add you answers as sympy matricies.\n", + "a1= \n", + "a2=\n", + "a3=\n", + "a4=\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "08acf30a", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (20810275.py, line 5)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Input \u001b[0;32mIn [7]\u001b[0;36m\u001b[0m\n\u001b[0;31m a1=sym.Matrix([[3x**2] ,[-2y]])\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "\n", + "##ANSWER##\n", + "x=2.2\n", + "y=2.3\n", + "\n", + "a1=sym.Matrix([[3x**2] ,[-2y]])\n", + "a2=sym.Matrix([[y^2+8yx^3] ,[2xy+2x^4])\n", + "a3=sym.Matrix([-sin(xy)y -sin(y)], [-sin(xy)x - xcos(y)])\n", + "a4=sym.Matrix([(1/y)-2z],[ -x/y^2], [3z^2-2x])\n", + "\n", + "##ANSWER##" + ] + }, + { + "cell_type": "markdown", + "id": "dd9c7fa5", + "metadata": {}, + "source": [ + "\\✅ **<span style=\"color:red\">Question:</span>** Example answercheck question: What is $x = 2+2$?\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "64684dfd", + "metadata": {}, + "outputs": [], + "source": [ + "#Put your answer here" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "619a2259", + "metadata": {}, + "outputs": [], + "source": [ + "##ANSWER##\n", + "x = 4\n", + "##ANSWER##" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "9cc2b34a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "CheckWarning: passed variable is <class 'int'> and not a numpy.matrix.\n", + " Trying to convert to a array matrix using ```A = np.matrix(A)```.\n", + "\n", + "\n", + "CheckWarning: passed matrix is int64 and not <class 'numpy.float64'>...\n", + " Trying to convert to float using ```A = A.astype(float)```.\n", + "\n", + "Testing [[4.]]\n", + "Answer seems to be correct\n", + "\n" + ] + } + ], + "source": [ + "from answercheck import checkanswer\n", + "checkanswer.vector(x,'2cab95d1b144d663bad1ce5c51020ae0')" + ] + }, + { + "cell_type": "markdown", + "id": "44b461a0", + "metadata": {}, + "source": [ + "---\n", + "\n", + "Written by <<YOUR NAME HERE>>, Michigan State University \n", + "As part of the Data Science Bridge Project \n", + " \n", + "<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc/4.0/88x31.png\" /></a><br />This work is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\">Creative Commons Attribution-NonCommercial 4.0 International License</a>." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "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.9.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- GitLab