SlideShare a Scribd company logo
A Mathematica Tutorial -
1. Basic Operations

   This Tutorial was created usig Mathematica 6.0. Some of
    the cells described below can only be performed in version 6.0.

      Note that Mathematica can be used as a word processor, a sophiticated calculator,
   a programming language that can be used for numerical calculations as well as symbolic
    calculations. It also includes a drawing tool that can be used to add whatever you like
    to your final document. You should do all of your homwork for this course in Mathematica.


    Mathematica at http : êê documents.wolfram.com ê mathematica
     Please read the online Practical Introduction to


   It is important that you also do the "First Five Minutes with Mathematica"
    tour provided on the Mathematica 6 Startup Palette.


   A complete online manual can be found by followng the menu item "Help" Ø
    "Documentation Center". This provides text
      descriptions for the various features as well as examples.

      The full manual for Mathematica can be
     downloaded from the Documentation web site as a pdf file.




Notebooks

   Mathematica documents are called "notebooks". They can contain text, commands, and graphics.

       All entries appear in "cells" which
      are delineated by brackets at the right side of the page.

       Various pre - set "styles" are availabe for your notebooks under the menu "Format" Ø
    "Stylesheet". Try them out to see which you prefer.

       The format of the text is controled by the
      user with various styles appearing under the menu item "Format" Ø
     "Style". In the section headings below the backgound color is "grey cell box".
2   Mathematica Tutorial 1.nb




Calculations and variables

         Start a new cell by clicking the cursor in an open
          space and type the text or calculation that you want to perform.
           Start by typing the following followed by hitting the "enter" key
          to evaluate the expression and obtain the answer in an output cell :


         2 + 2


         4



         Multiplication can be indcated by a space,
         e.g. 2 * 4 can be written with the asterisk, or with 2 ÿ 4


         2ÿ4


         8



         Exponentiation is indicated by the upward carrot sign :


         2^4


         16



         The most recent result of a calculation is symbolized by "%" :


         2%


         32



         A variable can be assigned a value with the equals sign :


         y = 2 ^ 6 + 32


         96




          it in an expression H or simply typing it followed by a returnL.
         You can obtain the value of a variable at anytime by using
Mathematica Tutorial 1.nb   3




    y


    96



    The value of any variable can be removed with a period following an equals sign :


    y =.


    y


    y




    Important :
    Note that many users of Mathematica can become confused by
     its performance since it does not normally function like a C or Fortran
     program by running from top to bottom. Keep in mind that it is a notebook,
    and once a variable or function is defined, it keeps that value even if you move back
     to a line above where it was most recently defined and perform another evaluation.




      initializationcells HKernel Ø Evaluation Ø Evaluate InitializationL. Select
    You can run a Mathematica notebook as a program from top to bottom by evaluating all the

      each cell that you want to specify as an Initialization Cell amd go to Cell Ø
     Cell Properties Ø Initialization Cell. The cell below is an initializatin
       cell since it has an I at the top of the cell bracket. The semicolon at the end
       of each line prevents that equality from being repeated as an output line.


    y = 2 Pi;
    x = 360;
    z = 2 ^ 24;




Functions defined in Mathematica

    Functions are indicated by keywords that are capitalized. Sin is a reserved
     word indicating the Sine function. The argument of a function is indicated
     in square brakets following the keyword. Pi is a reserved constant.Note that
     the first letter of reserved function or constant is always capitalized.


    Sin@2 PiD


    0
4   Mathematica Tutorial 1.nb




         The argument of trig functions is in radians by default.


         Sin@Pi ê 2D


         1




           argument HNote the unit Degree is always singular in MathematicaL :
         You can switch to degrees by writing "Degree" after the



         Sin@90 DegreeD


         1



         Numerical evaluation can be forced with the N@D function :


         Pi


         p



         N@PiD


         3.14159



         The level of precision can be specified as a second element in the N function.


         N@Pi, 100D


         3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280Ö
          34825342117068




Functions defined by the user

         You can define our own functions. Note that the definition specifies the
          variable on the left side in brackets with the underline following it. This is to
          be substituted into the expression on the right. The function can be used anywhere
          it is needed with the value for the variable explicitly indicated in brackets.


         ANewFunc@x_D := x ^ 2 + 2 x + 3
Mathematica Tutorial 1.nb   5




    y = ANewFunc@20D


    443



    The definition of any function can be removed with an equals sign followed by a period :


    ANewFunc@x_D =.


    y = ANewFunc@20D


    ANewFunc@20D




Logarithms

    The natural log of a number is obtained with the Log@D function :


    Log@10.0D


    2.30259



    The log of a number to the base 10 is obtained with the Log@10, xD :


    Log@10, 2.0D


    0.30103




Plotting

    Use the Plot function to plot the a function,
    with the limits for the plot indicated in curly brakets :
6   Mathematica Tutorial 1.nb




         Plot@Sin@xD, 8x, 0, 2 Pi<D


                           1


                       0.5



                                    1   2   3      4      5       6


                      -0.5


                         -1


         Ü Graphics Ü



         See the online documentation and manual for more complete control of axes and labels.


         Plot@Log@xD, 8x, 0, 6<D


                       2


                                1       2   3       4         5       6

                      -2

                      -4

                      -6

                      -8




         Ü Graphics Ü



         The Manipulate command permits the addition of a slide bar to a
          plot to allow real time adjustment of parameters. In the example below,
         the parameter is adjustable from 0 to 2 with the initial value set to 1.
Mathematica Tutorial 1.nb   7




    Manipulate@Plot@Sin@n xD, 8x, 0, 2 Pi<D, 88n, 1<, 0, 2<D




      n



           1.0



           0.5




                   1      2       3       4      5      6


          -0.5



          -1.0




    3 D plots are obtained with the Plot3D function :


    Plot3D@Sin@xD Cos@yD, 8x, 0, 2 Pi<, 8y, 0, 2 Pi<D




    Note : The plot can be selected and rotated in real time to change the view.
       The graphics output can be selected, copied,
    and pasted into a report or Powerpoint presentation.




Calculus
8   Mathematica Tutorial 1.nb




Calculus

         Derivatives can be calculated with the D@, D function
          with the first element indicating the function to be evaluated,

           to. Use the Basic Math Palettes for a more traditional input format Has shown hereL :
         and the second element indicating the variable the derivative is to be caluclated with respect




         ∂x x2


         2x



         ∂x Log@xD


         1
         x


         Integration is calculated with the Integrate@, D function with the
          function in the first element, and the variable to be integrated in the
          second element. The Basic Math Palette provides a traditional input format :



         ‡ x „x
            2




         x3
          3


         Note that these are indefinite integrals without
          limits. Definite integration with limits is also possible :



         ‡ x „x
             2
            2
          0



         8
         3




Data input and plotting

         The Directory@D command returns the current Directory :
Mathematica Tutorial 1.nb   9




Directory@D


êUsersêjohnshriver



You can also redefine the current directory :


SetDirectory@"êUsersêjohnshriverêDesktop"D


êUsersêjohnshriverêDesktop



Set up a matrix of x and y values using the "Insert" Ø "Table, Matrix" menu option,
or the Basic Math Palette :


           0    0
           1    2
           2   3.5
           3    4
Mydata =
           4   4.2
           5   4.3
           6   4.4
           7   4.4


880, 0<, 81, 2<, 82, 3.5<, 83, 4<, 84, 4.2<, 85, 4.3<, 86, 4.4<, 87, 4.4<<




 He.g. a WORD text file, or an Excel file, the data can be imported using the Import command :
If the data to be input is already in a file



Import@"testdata.dat", "Table"D


881, 1.1<, 82, 2.<, 83, 3.2<, 84, 3.9<, 85, 4.9<<



The above command could be modified to give the data set a name :


TestData = Import@"testdata.dat", "Table"D


881, 1.1<, 82, 2.<, 83, 3.2<, 84, 3.9<, 85, 4.9<<
10   Mathematica Tutorial 1.nb




        TableForm@TestDataD


        1   1.1
        2   2.
        3   3.2
        4   3.9
        5   4.9


        Data can also be Exported as a text file :


        Export@"output_test.txt", MydataD


        output_test.txt



        Export into an Excel format :


        Export@"output.xls", MydataD


        output.xls



        Plot data using the ListPlot Command instead of Plot :


        ListPlot@MydataD




        4



        3



        2



        1




                  1        2     3      4    5       6        7



        See Help for ListPlot options. Forexample,
        the point size can be controlled with the Prolog Ø AbsolutePointSize@D function.
             A frame on all four sides can be added with Frame Ø True.


        For later reference, the plot can be given a name :
Mathematica Tutorial 1.nb   11




    dataplot = ListPlot@Mydata, Prolog Ø AbsolutePointSize@5D, AxesLabel Ø 8time, absorbance<D


    absorbance


        4


        3


        2


        1


                                                             time
                     1   2   3   4       5       6       7



    ListPlot@Mydata, PlotJoined Ø TrueD




    4



    3



    2



    1




                 1       2   3       4       5       6        7




Data analysis - Fitting data

    A simple fit of the data using a linear least
     square routine could be obtained with the Fit function.


    Fit@Mydata, 81, x<, xD


    1.45833 + 0.540476 x



    Of course a linear fit of this data is not appropriate here. To
     obtain a nonlinear fit we need to load the Statistics Nonlinear package.
12   Mathematica Tutorial 1.nb




        Needs@"NonlinearRegression`"D;




          NonlinearFit@data, model, 8parameters<, 8variables<D
        The function NonlinearFit requires the following format :

        The model is the mathematical function which is assumed to describe
         the data. The list of variables and parameters follow. Typically,
        the variables list will only contain a single variable,
        while the parameters to be fit may contain two or more items.



         Hof course a linear fit would normally be accomplished the linear least squares program Fit@D,
        A simple example would be a fit of the above data with a linear equation

            but it works here as an introductory exampleL.


        NonlinearRegress@Mydata, a + b x, 8a, b<, xD



        :BestFitParameters Ø 8a Ø 1.45833, b Ø 0.540476<,


                                                        80.00911456, 2.90755< ,
                                 Estimate Asymptotic SE CI

                                                        80.194047, 0.886906<
          ParameterCITable Ø a   1.45833 0.592264
                             b   0.540476 0.141578
          EstimatedVariance Ø 0.841865,
                                              DF     SumOfSq      MeanSq
                       Model                  2      102.049      51.0244
          ANOVATable Ø Error                  6      5.05119      0.841865 ,
                       Uncorrected Total      8      107.1
                       Corrected Total        7      17.32

                                           1.       -0.83666
          AsymptoticCorrelationMatrix Ø                      ,
                                           -0.83666 1.
                                                      Curvature

                                                                >
                              Max Intrinsic           0
          FitCurvatureTable Ø
                              Max Parameter-Effects   0
                              95. % Confidence Region 0.440942




         Hthe user usually knows what function to fit the data to based on the experimental situation,
        A more appropriate function is normally obtained from an understanding of the experiment

            alternatively, he can fit the data to an arbitrary function, e.g. a polynomialL.
Mathematica Tutorial 1.nb   13




NonlinearRegress@Mydata, a x ê Hx + bL, 8a, b<, xD



:BestFitParameters Ø 8a Ø 5.4583, b Ø 1.33173<,


                                                  84.7451, 6.1715<
                           Estimate Asymptotic SE CI

                                                  80.692517, 1.97095<
    ParameterCITable Ø a   5.4583   0.291469                          ,
                       b   1.33173 0.261235
    EstimatedVariance Ø 0.0440968,
                                          DF       SumOfSq    MeanSq
                 Model                    2        106.835    53.4177
    ANOVATable Ø Error                    6        0.264581   0.0440968 ,
                 Uncorrected Total        8        107.1
                 Corrected Total          7        17.32

                                     1.       0.924797
    AsymptoticCorrelationMatrix Ø                      ,
                                     0.924797 1.
                                                Curvature

                                                          >
                        Max Intrinsic           0.0735356
    FitCurvatureTable Ø
                        Max Parameter-Effects   0.248355
                        95. % Confidence Region 0.440942


A plot of the fitted function Hwith the plot given a name "fit" hereL :


fit = Plot@5.45833 x ê H1.33177 + xL, 8x, 0, 7<D




4



3



2



1




          1      2     3       4      5        6       7



Overlay the data and the fitted function with the Show function :
14   Mathematica Tutorial 1.nb




        Show@dataplot, fitD


        absorbance


           4


           3


           2


           1


                                                             time
                     1      2    3      4    5     6     7




        NonlinearRegress@Mydata, a x ê Hx + bL, 8a, b<, x, ShowProgress Ø True,
         RegressionReport Ø 8BestFitParameters, ParameterCITable<D

Iteration:1 ChiSquared:4.96156 Parameters:85.46347, 2.69759<

Iteration:2 ChiSquared:2.16993 Parameters:85.20513, 0.628268<

Iteration:3 ChiSquared:0.311908 Parameters:85.36803, 1.16713<

Iteration:4 ChiSquared:0.264682 Parameters:85.4705, 1.33979<

Iteration:5 ChiSquared:0.264581 Parameters:85.45724, 1.33071<

Iteration:6 ChiSquared:0.264581 Parameters:85.45843, 1.33186<

Iteration:7 ChiSquared:0.264581 Parameters:85.45828, 1.33172<

Iteration:8 ChiSquared:0.264581 Parameters:85.4583, 1.33174<

Iteration:9 ChiSquared:0.264581 Parameters:85.4583, 1.33173<

Iteration:10 ChiSquared:0.264581 Parameters:85.4583, 1.33173<

Iteration:11 ChiSquared:0.264581 Parameters:85.4583, 1.33173<


        :BestFitParameters Ø 8a Ø 5.4583, b Ø 1.33173<,


                                                            84.7451, 6.1715<    >
                                     Estimate Asymptotic SE CI

                                                            80.692517, 1.97095<
          ParameterCITable Ø a       5.4583   0.291469
                             b       1.33173 0.261235

More Related Content

What's hot

Normal subgroups- Group theory
Normal subgroups- Group theoryNormal subgroups- Group theory
Normal subgroups- Group theory
Ayush Agrawal
 
Mathematical induction
Mathematical inductionMathematical induction
Mathematical induction
rey castro
 
composite functions
composite functionscomposite functions
composite functions
Glory Codilla
 
Power set
Power setPower set
Power set
Ahsan Raza
 
Section 11: Normal Subgroups
Section 11: Normal SubgroupsSection 11: Normal Subgroups
Section 11: Normal Subgroups
Kevin Johnson
 
Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)
Matthew Leingang
 
CMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical InductionCMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical Induction
allyn joy calcaben
 
Artificial Intelligence and Mathematics
Artificial Intelligence and MathematicsArtificial Intelligence and Mathematics
Artificial Intelligence and Mathematics
Balabhaskar Ashok Kumar
 
Graph theory presentation
Graph theory presentationGraph theory presentation
Graph theory presentation
Aliul Kadir Akib
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
AhsanIrshad8
 
Integration of GeoGebra in Teaching Mathematics
Integration of GeoGebra in Teaching MathematicsIntegration of GeoGebra in Teaching Mathematics
Integration of GeoGebra in Teaching Mathematics
Niroj Dahal
 
Matrix and its operation (addition, subtraction, multiplication)
Matrix and its operation (addition, subtraction, multiplication)Matrix and its operation (addition, subtraction, multiplication)
Matrix and its operation (addition, subtraction, multiplication)
NirnayMukharjee
 
Matrix Algebra seminar ppt
Matrix Algebra seminar pptMatrix Algebra seminar ppt
Matrix Algebra seminar ppt
Swetalina Pradhan
 
Integration by parts
Integration by partsIntegration by parts
Integration by parts
Елена Доброштан
 
Ppt of graph theory
Ppt of graph theoryPpt of graph theory
Ppt of graph theory
ArvindBorge
 
Laplace transformation
Laplace transformationLaplace transformation
Laplace transformation
Akanksha Diwadi
 
Venn Diagrams and Sets
Venn Diagrams and SetsVenn Diagrams and Sets
Venn Diagrams and Sets
Passy World
 
A method for solving quadratic programming problems having linearly factoriz...
A method for solving quadratic programming problems having  linearly factoriz...A method for solving quadratic programming problems having  linearly factoriz...
A method for solving quadratic programming problems having linearly factoriz...
IJMER
 

What's hot (20)

Normal subgroups- Group theory
Normal subgroups- Group theoryNormal subgroups- Group theory
Normal subgroups- Group theory
 
Mathematical induction
Mathematical inductionMathematical induction
Mathematical induction
 
composite functions
composite functionscomposite functions
composite functions
 
Power set
Power setPower set
Power set
 
Section 11: Normal Subgroups
Section 11: Normal SubgroupsSection 11: Normal Subgroups
Section 11: Normal Subgroups
 
Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)
 
CMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical InductionCMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical Induction
 
Artificial Intelligence and Mathematics
Artificial Intelligence and MathematicsArtificial Intelligence and Mathematics
Artificial Intelligence and Mathematics
 
Graph theory presentation
Graph theory presentationGraph theory presentation
Graph theory presentation
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
 
Integration of GeoGebra in Teaching Mathematics
Integration of GeoGebra in Teaching MathematicsIntegration of GeoGebra in Teaching Mathematics
Integration of GeoGebra in Teaching Mathematics
 
Matrix and its operation (addition, subtraction, multiplication)
Matrix and its operation (addition, subtraction, multiplication)Matrix and its operation (addition, subtraction, multiplication)
Matrix and its operation (addition, subtraction, multiplication)
 
11365.integral 2
11365.integral 211365.integral 2
11365.integral 2
 
Matrix Algebra seminar ppt
Matrix Algebra seminar pptMatrix Algebra seminar ppt
Matrix Algebra seminar ppt
 
Integration by parts
Integration by partsIntegration by parts
Integration by parts
 
Ppt of graph theory
Ppt of graph theoryPpt of graph theory
Ppt of graph theory
 
Laplace transformation
Laplace transformationLaplace transformation
Laplace transformation
 
Chapter 2 (maths 3)
Chapter 2 (maths 3)Chapter 2 (maths 3)
Chapter 2 (maths 3)
 
Venn Diagrams and Sets
Venn Diagrams and SetsVenn Diagrams and Sets
Venn Diagrams and Sets
 
A method for solving quadratic programming problems having linearly factoriz...
A method for solving quadratic programming problems having  linearly factoriz...A method for solving quadratic programming problems having  linearly factoriz...
A method for solving quadratic programming problems having linearly factoriz...
 

Viewers also liked

Parnu In Estonia
Parnu In EstoniaParnu In Estonia
Parnu In Estoniamerleudso
 
Youth in action programme
Youth in action programmeYouth in action programme
Youth in action programmeRoma Ilyniak
 
Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...
Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...
Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...
P_Kutsehariduskeskus
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentationRoma Ilyniak
 
Ylejoe Gymnasium Of Parnu 1
Ylejoe Gymnasium Of Parnu 1Ylejoe Gymnasium Of Parnu 1
Ylejoe Gymnasium Of Parnu 1merleudso
 
Young People In Estonia 5
Young People In Estonia 5Young People In Estonia 5
Young People In Estonia 5merleudso
 
プログラミングとMathematica
プログラミングとMathematicaプログラミングとMathematica
プログラミングとMathematica
Hirokazu Kobayashi
 
Parnu Koidula Gymnasium
Parnu Koidula GymnasiumParnu Koidula Gymnasium
Parnu Koidula Gymnasiumleibur
 
Emakeele viktoriin 1. kl
Emakeele viktoriin 1. klEmakeele viktoriin 1. kl
Emakeele viktoriin 1. kl
kaja oja
 
Le Piramidi dei numeri 1: Scopriamo la regola
Le Piramidi dei numeri 1: Scopriamo la regolaLe Piramidi dei numeri 1: Scopriamo la regola
Le Piramidi dei numeri 1: Scopriamo la regolaclapir
 
Mathematicaが敬遠される理由とは
Mathematicaが敬遠される理由とはMathematicaが敬遠される理由とは
Mathematicaが敬遠される理由とは
Hirokazu Kobayashi
 
Mathematica言語の原理
Mathematica言語の原理Mathematica言語の原理
Mathematica言語の原理
Hirokazu Kobayashi
 
People Skills
People SkillsPeople Skills
People Skills
Ramakanta Behera
 
HMB Jahrbuch 2015
HMB Jahrbuch 2015HMB Jahrbuch 2015
HMB Jahrbuch 2015
Historisches Museum Basel
 

Viewers also liked (15)

Parnu In Estonia
Parnu In EstoniaParnu In Estonia
Parnu In Estonia
 
Youth in action programme
Youth in action programmeYouth in action programme
Youth in action programme
 
Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...
Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...
Malle Kallus, Anne Metsmaa, Heli Hinrikson ja Maie Jesjutina: Läti kogemus pr...
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
 
Evening
EveningEvening
Evening
 
Ylejoe Gymnasium Of Parnu 1
Ylejoe Gymnasium Of Parnu 1Ylejoe Gymnasium Of Parnu 1
Ylejoe Gymnasium Of Parnu 1
 
Young People In Estonia 5
Young People In Estonia 5Young People In Estonia 5
Young People In Estonia 5
 
プログラミングとMathematica
プログラミングとMathematicaプログラミングとMathematica
プログラミングとMathematica
 
Parnu Koidula Gymnasium
Parnu Koidula GymnasiumParnu Koidula Gymnasium
Parnu Koidula Gymnasium
 
Emakeele viktoriin 1. kl
Emakeele viktoriin 1. klEmakeele viktoriin 1. kl
Emakeele viktoriin 1. kl
 
Le Piramidi dei numeri 1: Scopriamo la regola
Le Piramidi dei numeri 1: Scopriamo la regolaLe Piramidi dei numeri 1: Scopriamo la regola
Le Piramidi dei numeri 1: Scopriamo la regola
 
Mathematicaが敬遠される理由とは
Mathematicaが敬遠される理由とはMathematicaが敬遠される理由とは
Mathematicaが敬遠される理由とは
 
Mathematica言語の原理
Mathematica言語の原理Mathematica言語の原理
Mathematica言語の原理
 
People Skills
People SkillsPeople Skills
People Skills
 
HMB Jahrbuch 2015
HMB Jahrbuch 2015HMB Jahrbuch 2015
HMB Jahrbuch 2015
 

Similar to Mathematica tutorial 3

Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998
Vinit Rajput
 
2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica2D & 3D Modelling with Mathematica
2D & 3D Modelling with MathematicaMiles Ford
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 
Mmc manual
Mmc manualMmc manual
Mmc manual
Urvi Surat
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
Lincoln Hannah
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
abelmeketa
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
Principal Component Analysis(PCA) understanding document
Principal Component Analysis(PCA) understanding documentPrincipal Component Analysis(PCA) understanding document
Principal Component Analysis(PCA) understanding document
Naveen Kumar
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
Naveed Rehman
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohan Raj
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
eAssessment in Practice Symposium
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
MOHAMMAD SAYDUL ALAM
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
Matlab Assignment Experts
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 
5 octave tutorial
5 octave tutorial5 octave tutorial
5 octave tutorial
TanmayVijay1
 

Similar to Mathematica tutorial 3 (20)

Matlab1
Matlab1Matlab1
Matlab1
 
Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998
 
2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
Principal Component Analysis(PCA) understanding document
Principal Component Analysis(PCA) understanding documentPrincipal Component Analysis(PCA) understanding document
Principal Component Analysis(PCA) understanding document
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
5 octave tutorial
5 octave tutorial5 octave tutorial
5 octave tutorial
 

Recently uploaded

Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Lviv Startup Club
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
FelixPerez547899
 
Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111
zoyaansari11365
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
daothibichhang1
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
agatadrynko
 
Set off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptxSet off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptx
HARSHITHV26
 
Digital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and TemplatesDigital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and Templates
Aurelien Domont, MBA
 
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Boris Ziegler
 
Brand Analysis for an artist named Struan
Brand Analysis for an artist named StruanBrand Analysis for an artist named Struan
Brand Analysis for an artist named Struan
sarahvanessa51503
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
dylandmeas
 
The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...
balatucanapplelovely
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdfBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
daothibichhang1
 
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdfikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
agatadrynko
 
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdfMeas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
dylandmeas
 
Cracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptxCracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptx
Workforce Group
 
FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134
LR1709MUSIC
 
Business Valuation Principles for Entrepreneurs
Business Valuation Principles for EntrepreneursBusiness Valuation Principles for Entrepreneurs
Business Valuation Principles for Entrepreneurs
Ben Wann
 
Enterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdfEnterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdf
KaiNexus
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
LuanWise
 

Recently uploaded (20)

Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
 
Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
 
Set off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptxSet off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptx
 
Digital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and TemplatesDigital Transformation and IT Strategy Toolkit and Templates
Digital Transformation and IT Strategy Toolkit and Templates
 
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
 
Brand Analysis for an artist named Struan
Brand Analysis for an artist named StruanBrand Analysis for an artist named Struan
Brand Analysis for an artist named Struan
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
 
The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...The effects of customers service quality and online reviews on customer loyal...
The effects of customers service quality and online reviews on customer loyal...
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdfBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
 
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdfikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
 
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdfMeas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
 
Cracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptxCracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptx
 
FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134
 
Business Valuation Principles for Entrepreneurs
Business Valuation Principles for EntrepreneursBusiness Valuation Principles for Entrepreneurs
Business Valuation Principles for Entrepreneurs
 
Enterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdfEnterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdf
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
 

Mathematica tutorial 3

  • 1. A Mathematica Tutorial - 1. Basic Operations This Tutorial was created usig Mathematica 6.0. Some of the cells described below can only be performed in version 6.0. Note that Mathematica can be used as a word processor, a sophiticated calculator, a programming language that can be used for numerical calculations as well as symbolic calculations. It also includes a drawing tool that can be used to add whatever you like to your final document. You should do all of your homwork for this course in Mathematica. Mathematica at http : êê documents.wolfram.com ê mathematica Please read the online Practical Introduction to It is important that you also do the "First Five Minutes with Mathematica" tour provided on the Mathematica 6 Startup Palette. A complete online manual can be found by followng the menu item "Help" Ø "Documentation Center". This provides text descriptions for the various features as well as examples. The full manual for Mathematica can be downloaded from the Documentation web site as a pdf file. Notebooks Mathematica documents are called "notebooks". They can contain text, commands, and graphics. All entries appear in "cells" which are delineated by brackets at the right side of the page. Various pre - set "styles" are availabe for your notebooks under the menu "Format" Ø "Stylesheet". Try them out to see which you prefer. The format of the text is controled by the user with various styles appearing under the menu item "Format" Ø "Style". In the section headings below the backgound color is "grey cell box".
  • 2. 2 Mathematica Tutorial 1.nb Calculations and variables Start a new cell by clicking the cursor in an open space and type the text or calculation that you want to perform. Start by typing the following followed by hitting the "enter" key to evaluate the expression and obtain the answer in an output cell : 2 + 2 4 Multiplication can be indcated by a space, e.g. 2 * 4 can be written with the asterisk, or with 2 ÿ 4 2ÿ4 8 Exponentiation is indicated by the upward carrot sign : 2^4 16 The most recent result of a calculation is symbolized by "%" : 2% 32 A variable can be assigned a value with the equals sign : y = 2 ^ 6 + 32 96 it in an expression H or simply typing it followed by a returnL. You can obtain the value of a variable at anytime by using
  • 3. Mathematica Tutorial 1.nb 3 y 96 The value of any variable can be removed with a period following an equals sign : y =. y y Important : Note that many users of Mathematica can become confused by its performance since it does not normally function like a C or Fortran program by running from top to bottom. Keep in mind that it is a notebook, and once a variable or function is defined, it keeps that value even if you move back to a line above where it was most recently defined and perform another evaluation. initializationcells HKernel Ø Evaluation Ø Evaluate InitializationL. Select You can run a Mathematica notebook as a program from top to bottom by evaluating all the each cell that you want to specify as an Initialization Cell amd go to Cell Ø Cell Properties Ø Initialization Cell. The cell below is an initializatin cell since it has an I at the top of the cell bracket. The semicolon at the end of each line prevents that equality from being repeated as an output line. y = 2 Pi; x = 360; z = 2 ^ 24; Functions defined in Mathematica Functions are indicated by keywords that are capitalized. Sin is a reserved word indicating the Sine function. The argument of a function is indicated in square brakets following the keyword. Pi is a reserved constant.Note that the first letter of reserved function or constant is always capitalized. Sin@2 PiD 0
  • 4. 4 Mathematica Tutorial 1.nb The argument of trig functions is in radians by default. Sin@Pi ê 2D 1 argument HNote the unit Degree is always singular in MathematicaL : You can switch to degrees by writing "Degree" after the Sin@90 DegreeD 1 Numerical evaluation can be forced with the N@D function : Pi p N@PiD 3.14159 The level of precision can be specified as a second element in the N function. N@Pi, 100D 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280Ö 34825342117068 Functions defined by the user You can define our own functions. Note that the definition specifies the variable on the left side in brackets with the underline following it. This is to be substituted into the expression on the right. The function can be used anywhere it is needed with the value for the variable explicitly indicated in brackets. ANewFunc@x_D := x ^ 2 + 2 x + 3
  • 5. Mathematica Tutorial 1.nb 5 y = ANewFunc@20D 443 The definition of any function can be removed with an equals sign followed by a period : ANewFunc@x_D =. y = ANewFunc@20D ANewFunc@20D Logarithms The natural log of a number is obtained with the Log@D function : Log@10.0D 2.30259 The log of a number to the base 10 is obtained with the Log@10, xD : Log@10, 2.0D 0.30103 Plotting Use the Plot function to plot the a function, with the limits for the plot indicated in curly brakets :
  • 6. 6 Mathematica Tutorial 1.nb Plot@Sin@xD, 8x, 0, 2 Pi<D 1 0.5 1 2 3 4 5 6 -0.5 -1 Ü Graphics Ü See the online documentation and manual for more complete control of axes and labels. Plot@Log@xD, 8x, 0, 6<D 2 1 2 3 4 5 6 -2 -4 -6 -8 Ü Graphics Ü The Manipulate command permits the addition of a slide bar to a plot to allow real time adjustment of parameters. In the example below, the parameter is adjustable from 0 to 2 with the initial value set to 1.
  • 7. Mathematica Tutorial 1.nb 7 Manipulate@Plot@Sin@n xD, 8x, 0, 2 Pi<D, 88n, 1<, 0, 2<D n 1.0 0.5 1 2 3 4 5 6 -0.5 -1.0 3 D plots are obtained with the Plot3D function : Plot3D@Sin@xD Cos@yD, 8x, 0, 2 Pi<, 8y, 0, 2 Pi<D Note : The plot can be selected and rotated in real time to change the view. The graphics output can be selected, copied, and pasted into a report or Powerpoint presentation. Calculus
  • 8. 8 Mathematica Tutorial 1.nb Calculus Derivatives can be calculated with the D@, D function with the first element indicating the function to be evaluated, to. Use the Basic Math Palettes for a more traditional input format Has shown hereL : and the second element indicating the variable the derivative is to be caluclated with respect ∂x x2 2x ∂x Log@xD 1 x Integration is calculated with the Integrate@, D function with the function in the first element, and the variable to be integrated in the second element. The Basic Math Palette provides a traditional input format : ‡ x „x 2 x3 3 Note that these are indefinite integrals without limits. Definite integration with limits is also possible : ‡ x „x 2 2 0 8 3 Data input and plotting The Directory@D command returns the current Directory :
  • 9. Mathematica Tutorial 1.nb 9 Directory@D êUsersêjohnshriver You can also redefine the current directory : SetDirectory@"êUsersêjohnshriverêDesktop"D êUsersêjohnshriverêDesktop Set up a matrix of x and y values using the "Insert" Ø "Table, Matrix" menu option, or the Basic Math Palette : 0 0 1 2 2 3.5 3 4 Mydata = 4 4.2 5 4.3 6 4.4 7 4.4 880, 0<, 81, 2<, 82, 3.5<, 83, 4<, 84, 4.2<, 85, 4.3<, 86, 4.4<, 87, 4.4<< He.g. a WORD text file, or an Excel file, the data can be imported using the Import command : If the data to be input is already in a file Import@"testdata.dat", "Table"D 881, 1.1<, 82, 2.<, 83, 3.2<, 84, 3.9<, 85, 4.9<< The above command could be modified to give the data set a name : TestData = Import@"testdata.dat", "Table"D 881, 1.1<, 82, 2.<, 83, 3.2<, 84, 3.9<, 85, 4.9<<
  • 10. 10 Mathematica Tutorial 1.nb TableForm@TestDataD 1 1.1 2 2. 3 3.2 4 3.9 5 4.9 Data can also be Exported as a text file : Export@"output_test.txt", MydataD output_test.txt Export into an Excel format : Export@"output.xls", MydataD output.xls Plot data using the ListPlot Command instead of Plot : ListPlot@MydataD 4 3 2 1 1 2 3 4 5 6 7 See Help for ListPlot options. Forexample, the point size can be controlled with the Prolog Ø AbsolutePointSize@D function. A frame on all four sides can be added with Frame Ø True. For later reference, the plot can be given a name :
  • 11. Mathematica Tutorial 1.nb 11 dataplot = ListPlot@Mydata, Prolog Ø AbsolutePointSize@5D, AxesLabel Ø 8time, absorbance<D absorbance 4 3 2 1 time 1 2 3 4 5 6 7 ListPlot@Mydata, PlotJoined Ø TrueD 4 3 2 1 1 2 3 4 5 6 7 Data analysis - Fitting data A simple fit of the data using a linear least square routine could be obtained with the Fit function. Fit@Mydata, 81, x<, xD 1.45833 + 0.540476 x Of course a linear fit of this data is not appropriate here. To obtain a nonlinear fit we need to load the Statistics Nonlinear package.
  • 12. 12 Mathematica Tutorial 1.nb Needs@"NonlinearRegression`"D; NonlinearFit@data, model, 8parameters<, 8variables<D The function NonlinearFit requires the following format : The model is the mathematical function which is assumed to describe the data. The list of variables and parameters follow. Typically, the variables list will only contain a single variable, while the parameters to be fit may contain two or more items. Hof course a linear fit would normally be accomplished the linear least squares program Fit@D, A simple example would be a fit of the above data with a linear equation but it works here as an introductory exampleL. NonlinearRegress@Mydata, a + b x, 8a, b<, xD :BestFitParameters Ø 8a Ø 1.45833, b Ø 0.540476<, 80.00911456, 2.90755< , Estimate Asymptotic SE CI 80.194047, 0.886906< ParameterCITable Ø a 1.45833 0.592264 b 0.540476 0.141578 EstimatedVariance Ø 0.841865, DF SumOfSq MeanSq Model 2 102.049 51.0244 ANOVATable Ø Error 6 5.05119 0.841865 , Uncorrected Total 8 107.1 Corrected Total 7 17.32 1. -0.83666 AsymptoticCorrelationMatrix Ø , -0.83666 1. Curvature > Max Intrinsic 0 FitCurvatureTable Ø Max Parameter-Effects 0 95. % Confidence Region 0.440942 Hthe user usually knows what function to fit the data to based on the experimental situation, A more appropriate function is normally obtained from an understanding of the experiment alternatively, he can fit the data to an arbitrary function, e.g. a polynomialL.
  • 13. Mathematica Tutorial 1.nb 13 NonlinearRegress@Mydata, a x ê Hx + bL, 8a, b<, xD :BestFitParameters Ø 8a Ø 5.4583, b Ø 1.33173<, 84.7451, 6.1715< Estimate Asymptotic SE CI 80.692517, 1.97095< ParameterCITable Ø a 5.4583 0.291469 , b 1.33173 0.261235 EstimatedVariance Ø 0.0440968, DF SumOfSq MeanSq Model 2 106.835 53.4177 ANOVATable Ø Error 6 0.264581 0.0440968 , Uncorrected Total 8 107.1 Corrected Total 7 17.32 1. 0.924797 AsymptoticCorrelationMatrix Ø , 0.924797 1. Curvature > Max Intrinsic 0.0735356 FitCurvatureTable Ø Max Parameter-Effects 0.248355 95. % Confidence Region 0.440942 A plot of the fitted function Hwith the plot given a name "fit" hereL : fit = Plot@5.45833 x ê H1.33177 + xL, 8x, 0, 7<D 4 3 2 1 1 2 3 4 5 6 7 Overlay the data and the fitted function with the Show function :
  • 14. 14 Mathematica Tutorial 1.nb Show@dataplot, fitD absorbance 4 3 2 1 time 1 2 3 4 5 6 7 NonlinearRegress@Mydata, a x ê Hx + bL, 8a, b<, x, ShowProgress Ø True, RegressionReport Ø 8BestFitParameters, ParameterCITable<D Iteration:1 ChiSquared:4.96156 Parameters:85.46347, 2.69759< Iteration:2 ChiSquared:2.16993 Parameters:85.20513, 0.628268< Iteration:3 ChiSquared:0.311908 Parameters:85.36803, 1.16713< Iteration:4 ChiSquared:0.264682 Parameters:85.4705, 1.33979< Iteration:5 ChiSquared:0.264581 Parameters:85.45724, 1.33071< Iteration:6 ChiSquared:0.264581 Parameters:85.45843, 1.33186< Iteration:7 ChiSquared:0.264581 Parameters:85.45828, 1.33172< Iteration:8 ChiSquared:0.264581 Parameters:85.4583, 1.33174< Iteration:9 ChiSquared:0.264581 Parameters:85.4583, 1.33173< Iteration:10 ChiSquared:0.264581 Parameters:85.4583, 1.33173< Iteration:11 ChiSquared:0.264581 Parameters:85.4583, 1.33173< :BestFitParameters Ø 8a Ø 5.4583, b Ø 1.33173<, 84.7451, 6.1715< > Estimate Asymptotic SE CI 80.692517, 1.97095< ParameterCITable Ø a 5.4583 0.291469 b 1.33173 0.261235