{ "cells": [ { "cell_type": "markdown", "id": "45469f87", "metadata": {}, "source": [ "# Welcome to Math 124!\n", "\n", "## Lewis Pan - math.berkeley.edu/~yllpan\n" ] }, { "cell_type": "markdown", "id": "fef93b86", "metadata": {}, "source": [ "### Office hour poll\n", "\n", "Plan: Your homework is due on Wednesdays 8am, projects due on Friday midnight so\n", "1. One OH on Monday/Tuesday, before hw due\n", "2. One OH on Thursday/Friday before project is due\n", "\n", "My time constraints:\n", "* Cannot do 12-1 any day\n", "* Cannot do Tuesday/Thursday 8-9:30, 2-3:30\n" ] }, { "cell_type": "markdown", "id": "e39811cc", "metadata": {}, "source": [ "Office hours will be:\n", "\n", "* 9-10:30 Monday\n", "* 2-3 Friday\n" ] }, { "cell_type": "markdown", "id": "2d0d0833", "metadata": {}, "source": [ "### Logistics for Section" ] }, { "cell_type": "markdown", "id": "71a5f47e", "metadata": {}, "source": [ "I am flexible on this - I am happy to go over any material people are confused by, give summaries of material, or even give you a headstart on material to come if you feel comfortable with the stuff already covered.\n", "\n", "On quizzes, I plan to do this at the end of each section. There will be 6 quizzes, each 15 minutes. Your lowest score will be dropped. If you have DSP arrangements please come and talk to me. The quizzes will be in person but I will upload them after on gradescope.\n", "\n", "Unfortunately section is on Wednesday **AFTER** your homework is due. If you have hw questions office hours is probably a better idea, although I would be happy to go over homework solutions in section also. " ] }, { "cell_type": "markdown", "id": "069f1722", "metadata": {}, "source": [ "### Julia installation" ] }, { "cell_type": "markdown", "id": "7297511b", "metadata": {}, "source": [ "Julia website: https://julialang.org/downloads/\n", "\n", "IJulia: https://julialang.github.io/IJulia.jl/stable/manual/installation/\n", "\n", "0. Download julia\n", "1. Open julia in terminal, or whatever environment is native to your OS\n", "2. type in `using Pkg`\n", "3. type in `Pkg.add(\"IJulia\")`\n", "\n", "This should install IJulia (only needs to be done once). To open a notebook:\n", "\n", "1. `using IJulia`\n", "2. `notebook()`\n", "\n", "Alternatively you can just stick to using datahub. The official version the class is using is 1.6.3 - although if you use an older version try to stick to one after 1.2 as the functionality before that is slightly different. I'm on 1.6.2 and everything works fine." ] }, { "cell_type": "markdown", "id": "6064daac", "metadata": {}, "source": [ "### Demo time - LaTeX (pronounced latech)" ] }, { "cell_type": "markdown", "id": "1e837ac7", "metadata": {}, "source": [ "There are two ways to write an equation,\n", "\n", "``\n", "\\begin{equation}\n", " ...\n", "\\end{equation}\n", "``\n", "\n", "``\n", "$$\n", " ...\n", "$$\n", "``" ] }, { "cell_type": "markdown", "id": "93814d4e", "metadata": {}, "source": [ "\\begin{equation}\n", " 1+1 = 2\n", "\\end{equation}\n", "\n", "$$\n", " 1+1 = 2\n", "$$" ] }, { "cell_type": "markdown", "id": "24f21650", "metadata": {}, "source": [ "Here is a list of common things:\n", "\n", "1. Commands predicated w/ backslash \\\n", "2. Subscript, superscript is done with _ ^\n", "3. For example integral sign is \\int\n", "4. Summation sign is given by \\sum\n", "5. Infinity is \\infty\n", "6. Fraction \\frac{}{}\n", "7. Power is also ^\n", "8. Greek letters, backslash + spell it out e.g. \\pi\n", "9. https://www.overleaf.com/learn/latex/Matrices" ] }, { "cell_type": "markdown", "id": "8ea7bfbf", "metadata": {}, "source": [ "For example:\n", "$$ \n", " \\int_0^1 x dx = \\frac{1}{2} \\\\\n", " \\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6} \\\\\n", "$$" ] }, { "cell_type": "markdown", "id": "bab6115c", "metadata": {}, "source": [ "For more latex things, google is your best friend - I forget what the commands are all the time. Any questions?\n" ] }, { "cell_type": "markdown", "id": "c1174048", "metadata": {}, "source": [ "### Markdown things:\n", "\n", "1. Headers is #\n", "2. Bolding stuff **bold stuff**\n", "3. Italics is *italic stuff*\n", "4. Both **_both_**" ] }, { "cell_type": "markdown", "id": "8ea150e9", "metadata": {}, "source": [ "### More demo - Coding!" ] }, { "cell_type": "markdown", "id": "55856a69", "metadata": {}, "source": [ "Basic Types:\n", "1. Integers\n", "2. Float64/Double - Floating point numbers, i.e. decimals (3.14159)\n", "3. Strings - This is basically text (\"This is a string.\")\n", "4. Arrays - Lists of things" ] }, { "cell_type": "markdown", "id": "48186a31", "metadata": {}, "source": [ "Printing is one of the most important tools - it is extremely helpful for debugging. \n", "\n", "``\n", "println(\"This stuff here will be printed.\")\n", "println(480)\n", "``" ] }, { "cell_type": "code", "execution_count": 2, "id": "5f3ec580", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This stuff here will be printed.\n", "480\n" ] } ], "source": [ "### Printing a string, if you are inputting the string it needs to be surrounded by \"\"\n", "println(\"This stuff here will be printed.\")\n", "\n", "### Printing an integer\n", "println(480)" ] }, { "cell_type": "markdown", "id": "534eb6bd", "metadata": {}, "source": [ "The basic arithmetic operations are given by +,-,*,/ \n", "\n", "```\n", "1+1\n", "2-1\n", "8/3\n", "1.23*3\n", "```\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "86e4454b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.69" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1+1\n", "2-1\n", "8/3\n", "1.23*3" ] }, { "cell_type": "markdown", "id": "55d3473b", "metadata": {}, "source": [ "Why did they not all show up? In jupyter only the last thing evaluated will show up unless you print it explicitly." ] }, { "cell_type": "code", "execution_count": 4, "id": "a7b65c84", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n", "1\n", "2.6666666666666665\n", "3.69\n" ] } ], "source": [ "println(1+1)\n", "println(2-1)\n", "println(8/3)\n", "println(1.23*3)" ] }, { "cell_type": "markdown", "id": "feca7611", "metadata": {}, "source": [ "Even though you supply integers, the result will not necessarily stay the same type unlike in some other languages. In this case 8/3 automatically is cast into a float in Julia." ] }, { "cell_type": "markdown", "id": "ddc5f704", "metadata": {}, "source": [ "Setting variables is done with `=`:\n", "\n", "``\n", "var1 = 1;\n", "var2 = 100;\n", "var3 = 1000;\n", "var1 + var2\n", "``" ] }, { "cell_type": "code", "execution_count": 5, "id": "5a4c47d3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "101" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var1 = 1;\n", "var2 = 100;\n", "var3 = 1000;\n", "var1 + var2" ] }, { "cell_type": "markdown", "id": "a3e558e2", "metadata": {}, "source": [ "It is **VERY** good practice to name your variables something descriptive. What I just did is actually terrible practice. If you are working on a long project keeping track of what var1... means is not only tedious, but say you leave it for a while and then pick it up again later, you will forget what it means. I have done this before and have had to deal with a very upset supervisor as a result." ] }, { "cell_type": "markdown", "id": "1aca0657", "metadata": {}, "source": [ "Let's try and define a function now for this mathematical expressions:\n", "\n", "$$ \n", " f(x) = 1 - \\frac{x^2}{2!} + \\frac{x^4}{4!}\n", "$$" ] }, { "cell_type": "markdown", "id": "3ca64e22", "metadata": {}, "source": [ "Function definition is done like so:\n", "\n", "``\n", "function cosApprox( x )\n", " ...\n", " return ...\n", "end\n", "``\n", "\n", "A function will take in an argument and return another value." ] }, { "cell_type": "code", "execution_count": 1, "id": "6bb0915f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "cosApprox (generic function with 1 method)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function cosApprox( x )\n", " sum = 1;\n", " sum -= x^2 / 2;\n", " sum += x^4 / ( 1*2*3*4 );\n", " return sum\n", "end" ] }, { "cell_type": "code", "execution_count": 2, "id": "289265fb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.9950041666666667" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cosApprox(0.1)" ] }, { "cell_type": "code", "execution_count": 3, "id": "0060756d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.9800666666666666" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cosApprox(0.2)" ] }, { "cell_type": "code", "execution_count": null, "id": "c769f3c0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.6.2", "language": "julia", "name": "julia-1.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.6.2" } }, "nbformat": 4, "nbformat_minor": 5 }