diff --git a/notebooks/sagemath_guide.ipynb b/notebooks/sagemath_guide.ipynb index 5ff452e..d4babd2 100644 --- a/notebooks/sagemath_guide.ipynb +++ b/notebooks/sagemath_guide.ipynb @@ -219,6 +219,7 @@ } ], "source": [ + "# Sage provides basic math operations\n", "print(2**3)\n", "print(2^3)\n", "print(10 % 3) # ^ is a synonym for ** (unlike in Python)\n", @@ -226,6 +227,102 @@ "print(10//4) # for integer arguments, % means mod, i.e., remainder" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.84390889145858\n", + "-0.912021158525540\n", + "1/2*sqrt(3)\n" + ] + } + ], + "source": [ + "# Many Familiar mathematical functions\n", + "print(sqrt(3.4))\n", + "print(sin(5.135))\n", + "print(sin(pi/3))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e^2\n", + "7.38905609893065\n", + "1.77245385090552\n", + "-0.54402\n", + "-0.5440211109\n", + "3.1415926535897932384626433832795028841971693993751058209749\n" + ] + } + ], + "source": [ + "# To get numerical approximation use either N, aka numerical_approx,\n", + "# or method n (function N same as n)\n", + "# optional arguments:\n", + "# prec - requested # of bits of precision\n", + "# digits - requested # of decimal digits of precision, default is 53\n", + "print(exp(2))\n", + "print(n(exp(2)))\n", + "print(sqrt(pi).numerical_approx())\n", + "print(sin(10).n(digits=5))\n", + "print(N(sin(10),digits=10))\n", + "print(numerical_approx(pi, prec=200))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\n" + ] + } + ], + "source": [ + "a = 5 # a is an integer\n", + "print(type(a))\n", + "a = 5/3 # now a is a rational number\n", + "print(type(a))\n", + "a = 'hello' # now a is a string\n", + "print(type(a))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Getting Help\n", + "\n", + "Access built-in documentation, accessible by typing name of function or constant, followed by question mark" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "tan?" + ] + }, { "cell_type": "code", "execution_count": null,