01 Introduction

download 01 Introduction

of 57

description

nn

Transcript of 01 Introduction

  • Slide 1 of 291. Introduction to Mathematica

    A FIRST COURSE IN MATHEMATICA

    What Is Mathematica?

    Mathematica is a tool for technical computing that is used by mathematicians, engineers, analysts,and many others around the world. It contains an extensive knowledge base for working with a verybroad range of tasks, including solving equations, programming, importing and exporting data,visualizing functions and data, and much more.

    5

  • Slide 2 of 29What Is Mathematica: Some examples

    Lets take a moment and see what sorts of things Mathematica excels at. We dont expect you to fullyunderstand all of these examples at this point but by the end of this course, you should feelcomfortable creating and working with these sorts of computations.

    Calculate

    Input using free-form English

    In[9]:= 500 digits of pi

    Number line

    Out[9]= 2.5 3.0 3.5 4.0

    In[4]:= Plot@Sin@xD, 8x, 0, 2 * Pi

  • In[6]:= 1

    2

    Sin@xD xOut[6]= Cos@1D - Cos@2D

    In[10]:= 500 digits of Pi

    N@Pi, 500DOut[10]= 3.14159265358979323846264338327950288419716939937510582097494

    459230781640628620899862803482534211706798214808651328230664

    709384460955058223172535940812848111745028410270193852110555

    964462294895493038196442881097566593344612847564823378678316

    527120190914564856692346034861045432664821339360726024914127

    372458700660631558817488152092096282925409171536436789259036

    001133053054882046652138414695194151160943305727036575959195

    309218611738193261179310511854807446237996274956735188575272

    48912279381830119491

    In[11]:= Solve a*x^2+b*x+c equal to zero

    Results (1 of 3)

    Reduce@c + b*x + a*x^2 == 0, xDInput interpretation:

    1. INTRODUCTION

    7

  • In[11]:=

    Input interpretation:

    solve a x2 + b x + c 0

    Results:

    Reduce@c + b*x + a*x^2 == 0, xD

    a 0 and x - b2 - 4 a c + b

    2 a

    Reduce@c + b*x + a*x^2 == 0, xD

    a 0 and x b2 - 4 a c - b

    2 a

    Reduce@c + b*x + a*x^2 == 0, xDa 0 and b 0 and x - c

    b

    Possible intermediate steps:

    Solve for x:

    a x2 + b x + c 0

    M101: A FIRST COURSE IN MATHEMATICA

    8

  • In[11]:=

    Divide both sides by a:

    x2 +

    b x

    a

    +c

    a

    0

    Subtractc

    a

    from both sides:

    x2 +

    b x

    a

    - ca

    Addb2

    4 a2to both sides:

    x2 +

    b x

    a

    +b2

    4 a2 b2

    4 a2-c

    a

    Write the left hand side as a square:

    x +b

    2 a

    2 b24 a2

    -c

    a

    1. INTRODUCTION

    9

  • In[11]:=

    Take the square root of both sides:

    x +b

    2 a b2

    4 a2-c

    a

    or x +b

    2 a - b2

    4 a2-c

    a

    Subtractb

    2 afrom both sides:

    x b24 a2

    -c

    a

    -b

    2 aor x +

    b

    2 a - b2

    4 a2-

    Subtractb

    2 afrom both sides:

    Answer:

    x b24 a2

    -c

    a

    -b

    2 aor

    x - b2 a

    -

    M101: A FIRST COURSE IN MATHEMATICA

    10

  • In[11]:=

    Out[11]= a 0 && x -b - b2 - 4 a c

    2 a x -b + b2 - 4 a c

    2 a

    a 0 && b 0 && x -c

    b Hc 0 && b 0 && a 0L

    Use the Basic Math Assistant palette (select from the Palettes menu) to enter traditionalmathematical expressions.

    In[7]:= Sin@60 DSin@60 D

    Out[7]=

    3

    2

    Out[8]=

    3

    2

    1. INTRODUCTION

    11

  • Import, visualize, and process data

    Import an image from NASA of the planet Jupiter.

    In[12]:= img = Import@"http:www.nasa.govimagescontent507898main_PIA04866-

    full_full.jpg"D

    Out[12]=

    M101: A FIRST COURSE IN MATHEMATICA

    12

  • Take the digital negative of the image.

    In[13]:= ColorNegate@imgD

    Out[13]=

    Screen (or filter) data

    Find members of the Dow Jones Industrials with both large market cap and small price-to-earnings ratios.

    In[15]:= names = SelectAFinancialData@"^DJI", "Members"D,IFinancialData@, "MarketCap"D > 150 109 &&FinancialData@, "PERatio"D < 25 &ME

    Out[15]= 8CVX, GE, IBM, JNJ, JPM, KO, MSFT, PFE, PG, WMT, XOM Text (Alt + 7)

    FinancialData@"JK:BBCA"DH* this is the price of Bank BCA *LOut[17]= 9850

    Construct and analyze statistical models

    Import some sample data.

    In[18]:= data = Import@"sampledata.xls", 8"XLS", "Data", 1

  • Fit a nonlinear model to the data:

    In[23]:= nlm = NonlinearModelFitBdata, ExpB a xb + c x

    F, 8a, b, c

  • Dynamically manipulate data

    For all the countries of the world, import and show a graph of the GDP and population growthfrom 1970 to 2009.

    In[26]:= Manipulate@DateListPlot@CountryData@c, 8property, 81970, 2009

  • Although Mathematica is a very large and powerful system, you can get up and running with it in justa few minutes and become fairly proficient by learning some basic concepts about how it is orga-nized, the syntax of its commands, and how to get help when you are stuck. This course will guideyou through these first steps and provide you with the foundation you need to incorporate Mathemat-ica into your work and/or teaching.

    In[30]:= $ImportFormats

    Out[30]= 83DS, ACO, Affymetrix, AgilentMicroarray, AIFF, ApacheLog,ArcGRID, AU, AVI, Base64, BDF, Binary, Bit, BMP, Byte, BYU,

    BZIP2, CDED, CDF, Character16, Character8, CIF, Complex128,

    Complex256, Complex64, CSV, CUR, DBF, DICOM, DIF, DIMACS,

    Directory, DOT, DXF, EDF, EPS, ExpressionML, FASTA, FASTQ,

    FCS, FITS, FLAC, GenBank, GeoTIFF, GIF, GPX, Graph6, Graphlet,

    GraphML, GRIB, GTOPO30, GXL, GZIP, HarwellBoeing, HDF,

    HDF5, HIN, HTML, ICC, ICNS, ICO, ICS, Integer128, Integer16,

    Integer24, Integer32, Integer64, Integer8, JCAMP-DX,

    JPEG, JPEG2000, JSON, JVX, KML, LaTeX, LEDA, List, LWO,

    MAT, MathML, MBOX, MDB, MGF, MIDI, MMCIF, MOL, MOL2, MPS,

    MTP, MTX, MX, NASACDF, NB, NDK, NetCDF, NEXUS, NOFF, OBJ,

    ODS, OFF, OpenEXR, Package, Pajek, PBM, PCX, PDB, PDF, PGM,

    PLY, PNG, PNM, PPM, PXR, QuickTime, RawBitmap, Real128,

    Real32, Real64, RIB, RSS, RTF, SCT, SDF, SDTS, SDTSDEM, SFF,

    SHP, SMILES, SND, SP3, Sparse6, STL, String, SurferGrid,

    SXC, Table, TAR, TerminatedString, Text, TGA, TGF, TIFF,

    TIGER, TLE, TSV, UnsignedInteger128, UnsignedInteger16,

    UnsignedInteger24, UnsignedInteger32, UnsignedInteger64,

    UnsignedInteger8, USGSDEM, UUE, VCF, VCS, VTK, WAV, Wave64,

    WDX, XBM, XHTML, XHTMLMathML, XLS, XLSX, XML, XPORT, XYZ, ZIP