{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 5, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 5, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 5, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 5, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 5, "metadata": { }, "output_type": "execute_result" } ], "source": [ "var('x,y')\n", "f(x,y) = e^(-x^2 * y)\n", "show(f)\n", "df_dx = f.diff()[0]\n", "show(df_dx)\n", "df_dy = f.diff()[1]\n", "show(df_dy)\n", "\n", "show(f.diff(2))\n", "show(f.diff(2)[1,0])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Z0: 1\n", "0 0\n" ] }, { "data": { "text/html": [ "" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": "\n\n" }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" } ], "source": [ "z0 = f(0,0)\n", "print 'Z0:', z0\n", "x_slope = df_dx(0,0)\n", "y_slope = df_dy(0,0)\n", "print x_slope, y_slope\n", "x0 = 0\n", "y0=0\n", "Z(x,y) = z0 + x_slope*(x - x0) + y_slope*(y-y0)\n", "show(Z)\n", "\n", "f_plot = plot3d(f, (x, -1, 1), (y, -1, 1), color='red')\n", "t_plot = plot3d(Z, (x, -1, 1), (y, -1, 1), color='blue')\n", "f_plot + t_plot\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Z0: e^(-1)\n", "-2*e^(-1) -e^(-1)\n" ] }, { "data": { "text/html": [ "" ] }, "execution_count": 14, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": "\n\n" }, "execution_count": 14, "metadata": { }, "output_type": "execute_result" } ], "source": [ "#A -e\n", "z0 = f(1,1)\n", "print 'Z0:', z0\n", "x_slope = df_dx(1,1)\n", "y_slope = df_dy(1,1)\n", "print x_slope, y_slope\n", "x0 = 1\n", "y0=1\n", "Z(x,y) = z0 + x_slope*(x - x0) + y_slope*(y-y0)\n", "show(Z)\n", "\n", "f_plot = plot3d(f, (x, 0, 2), (y, 0, 2), color='red')\n", "t_plot = plot3d(Z, (x, 0, 2), (y, 0, 2))\n", "f_plot + t_plot" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "# Q2" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": "\n\n" }, "execution_count": 31, "metadata": { }, "output_type": "execute_result" } ], "source": [ "#a\n", "var('x,y')\n", "f(x, y) = 4\n", "plot3d(f, (x, -2, 2), (y, -2, 2))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Z0: 0\n", "0 0\n" ] }, { "data": { "text/html": [ "" ] }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": "\n\n" }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" } ], "source": [ "f(x,y) = x^2 + y^2\n", "\n", "z0 = f(0,0)\n", "print 'Z0:', z0\n", "x_slope = f.diff()[0](0,0)\n", "y_slope = f.diff()[1](0,0)\n", "print x_slope, y_slope\n", "x0 = 1\n", "y0=1\n", "Z(x,y) = z0 + x_slope*(x - x0) + y_slope*(y-y0)\n", "show(Z)\n", "\n", "f_plot = plot3d(f, (x, -1, 1), (y, -1, 1), color='red')\n", "t_plot = plot3d(Z, (x, -1, 1), (y, -1, 1))\n", "f_plot + t_plot" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": "\n\n" }, "execution_count": 26, "metadata": { }, "output_type": "execute_result" } ], "source": [ "var('y')\n", "f(x,y) = x^3 * y - x^2\n", "plot_f = plot3d(f, (x, -1, 1), (y, -1 , 1))\n", "plot_f" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 30, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 30, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 30, "metadata": { }, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "(1,1) for dY/dL: 1.50000000000000\n", "(1,1) for dY/dK: 0.500000000000000\n", "(1000,1000000) for dY/dL: 8.43511987785524\n", "(1000,1000000) for dY/dK: 0.00281170662595175\n", "(1000,1) for dY/dL: 0.266741911505838\n", "(1000,1) for dY/dK: 88.9139705019461\n", "(1,100000) for dY/dL: 26.6741911505838\n", "(1,100000) for dY/dK: 0.0000889139705019461\n" ] } ], "source": [ "var('L, K')\n", "Y(L, K) = 2*L^0.75 * K^0.25\n", "show(Y)\n", "\n", "dY_dL = Y.diff()[0]\n", "dY_dK = Y.diff()[1]\n", "show(dY_dL)\n", "show(dY_dK)\n", "\n", "print '(1,1) for dY/dL:', dY_dL(1 ,1)\n", "print '(1,1) for dY/dK:', dY_dK(1 ,1)\n", "\n", "print '(1000,1000000) for dY/dL:', dY_dL(1000,1000000)\n", "print '(1000,1000000) for dY/dK:', dY_dK(1000,1000000)\n", "\n", "\n", "print '(1000,1) for dY/dL:', dY_dL(1000,1)\n", "print '(1000,1) for dY/dK:', dY_dK(1000,1)\n", "\n", "print '(1,100000) for dY/dL:', dY_dL(1,100000)\n", "print '(1,100000) for dY/dK:', dY_dK(1,100000)\n", "\n" ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 8.3", "name": "sage-8.3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15" } }, "nbformat": 4, "nbformat_minor": 0 }