Julia_BasicsA.ipynb.txt - "cells"cell_type"markdown"metadata"collapsed true"hide_input true"source Part 1 Using Julia as a Glorified Calculator\n\n

Julia_BasicsA.ipynb.txt -...

This preview shows page 1 - 7 out of 22 pages.

{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true, "hide_input": true }, "source": [ "# Part 1: Using Julia as a Glorified Calculator\n", "\n", "## Basics\n", "\n", "Julia can be used like a whole bunch of different programms to do basic arithmetic" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Addition\n", "\n", "1+1" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Subtraction\n", "\n", "4-1 " ] }, { "cell_type": "code", "execution_count": 6,
Image of page 1

Subscribe to view the full document.

"metadata": {}, "outputs": [ { "data": { "text/plain": [ "15" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Multiplication\n", "\n", "5*3" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Division\n", "6/3 " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Raising a number to a power\n", "\n", "2^3" ] }, { "cell_type": "code",
Image of page 2
"execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Square Root\n", "\n", "sqrt(4)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "π = 3.1415926535897..." ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Special number pi\n", "pi" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "e = 2.7182818284590..." ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Special number e=exp(1)\n", "e" ] }, { "cell_type": "markdown",
Image of page 3

Subscribe to view the full document.

"metadata": {}, "source": [ "## Arrays\n", "\n", "We can also do calculations on lots of numbers at once. The first of these are arrays.\n", "\n", "Arrays are essentially just collections of numbers in a table. We'll use these a lot later on, when we talk about matrices and vectors.\n", "\n", "To write an array, simply write a list of numbers separated by spaces or semicolons (;), surrounded by square brackets ([ ])" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5-element Array{Int64,1}:\n", " 1\n", " 2\n", " 3\n", " 4\n", " 5" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If you use semicolons, you get a result in a single column\n", "\n", "# We'll introduce variables (this x= business) in a minute\n", "x = [1;2;3;4;5]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1×5 Array{Int64,2}:\n", " 1 2 3 4 5" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If you use spaces, you get results in a single row\n", "y=[1 2 3 4 5]" ] },
Image of page 4
{ "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×3 Array{Int64,2}:\n", " 1 2 3\n", " 4 5 6" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We can use spaces and semicolons to make tables of numbers:\n", "\n", "z = [1 2 3 ; 4 5 6]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we want to get a particular cell of the array z, we can call it using z[row,column] like:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z[2,3]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On top of that, we can also change values stored in particular cells:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [
Image of page 5

Subscribe to view the full document.

{ "data": {
Image of page 6
Image of page 7
  • Spring '12
  • Boman

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes