4/30/2017
FJ Tutorial Mathematica
FJ Mathematica Tutorial
Symbolic calculation
Mathematica notebook
Mathematica programming language
Graphics
Simple Linear Regression
Algebra
Calculus
Statistics
Linear Algebra
Differential Equations: DSolve[], NDSolve[]
Optimization
Root Finding and Fitting
Symbolic calculation
Beside numerical computation Mathematica is known for its symbolic computation. It does algebra, calculus, differential equations and more. For example, to
integrate calculate , create an code “input cell”, type in it Integrate[x^n,x] and press <Shift+Enter> .
As another example, you can factor an algebraic equation: Also Expand[] and Simplify[]
Or, you can solve (both numerically and symbolically) algebraic (or differential) equations, e.g., for a simple quadratic equation we get the standard solution:
Mathematica notebook
A Mathematica notebook is a presentation plus a program all in one document. It usually contains (formatted) text, equations, computations, and plots. This is
an example of a Mathematica notebook. The file has extension .nb..
Cells and keyboard shortcut to create a new cell
When you press the down arrow key at the end of an exiting cell, a ⊕ sign appears enabling you to create the type of the cell. If you just start typing, then the
cell is by default an input cell, i.e., where you enter Mathematica commands. After you enter a command, you press <shift + enter> to run it. Besides input
cells, you can choose cells of type Text, Title, Section, Subsection, etc., by clicking on ⊕. However, it is easier to use shortcut keys (on Mac <cmd+a number>,
on Window <cmd + a number>):
Section = <cmd+4>
Subsection = < cmd+5>
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 1/48
4/30/2017
FJ Tutorial Mathematica
Subsubsection = < cmd+6>
Text = <cmd +7>
Spell checking a notebook
Spell checker is under the Edit menu. (You can also use the keyboard shortcut <cmd + ;>.)
Getting help
To learn about a function click Help on the toolbar and enter the name of the function in the search field and then look especially at the examples. For a short
description you also enter ? followed by the function name in an input cell, and then click on >> for detailed explanation e.g.,
Mathematica programming language
Like most other scientific computing platforms, Mathematica has an interactive environment. You can assign to variables and call builtin functions or create
and call your own functions. Its data structures include lists and matrices.
Lists
Like Python, a basic data structure is a list. But, unlike Python. lists are enclosed in curly brackets as {1, 4, 3, 2.1} (rather than in square bracket [ ]). For
example:
Drop[] and Take[] return a part of list, e.g.
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 2/48
4/30/2017
FJ Tutorial Mathematica
Some element testing functions are Position[], Count[], MemberQ[], e.g.
Some list modifying functions are: Prepend[], Append[], Insert, Delete[], ReplacePart[], Join[], Union[], etc., Flatten[], Sort[], Ordering[], Reverse[], RotateLeft[],
Partition[], Split[], Permutations[],
Generating Lists
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 3/48
4/30/2017
FJ Tutorial Mathematica
Selecting from a list
Criticism: 3 > 4 returns true, but aList > 4 does not return a Boolean list. Instead must do
Matrices
A matrix is list of lists. You use them a lot in data analysis and linear regression. For example, the following is a 3 by 2 matrix (3 rows, 2 columns).
You can display its matrix form by
Second Column of mat32
Expressions
Expression can be handled like lists, e.g.,
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 4/48
4/30/2017
FJ Tutorial Mathematica
Random numbers
Probability
Assignments
x:= a creates an alias of a, i.e., a reference to a that persist when a changes
Functions
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 5/48
4/30/2017
FJ Tutorial Mathematica
Mathematica has thousands of builtin functions. Unlike other language which use parenthesis, Mathematica uses square bracket to enclose function
arguments, as in Sin[x] or Log[2.72]. Mathematica functions usually have long name, but as you type the name a list pops up and you can select the function
name from the list and press <Enter>.
Examples of built-in functions
The functions Mean[x] and StandardDeviation[x] calculate the mean (average) and standard deviation of a list of numbers. For example,
These functions can also be applied to matrices. For example Mean[mat32] calculates the mean of each column of the matrix mat32:
User defined functions
The simple unction add1[x] below just adds 1 to x. You call this function the same way as you call a builtin function:
You can also invoke a function f[x] in postfix form x // f or f[x,y] in infix form x ~ f ~ y:
You can also apply this function to lists and matrices:
A function returning 2 values
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 6/48
4/30/2017
FJ Tutorial Mathematica
Functions can be rule based:
Function defined by “=” instead of “:=”
Assignment “=” to a function provides the giving the final “value” of an expression. I would say, avoid it:
Functions with default and optional values
Functions with default value
Function with Optional values
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 7/48
4/30/2017
FJ Tutorial Mathematica
Functions That Remember Values They Have Found
Global`fib
fib[0]=1
fib[1]=1
fib[2]=2
fib[3]=3
fib[4]=5
fib[5]=8
fib[x_]:=fib[x]=fib[x-1]+fib[x-2]
Anonymous functions (“pure functions”)
Apply and Map
Composition[f,g,..], InverseFunction[f]
A useful summary statistics function
The following simple summary statistics function useful in your reports
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 8/48
4/30/2017
FJ Tutorial Mathematica
You can use it both on lists and on matrices (with any number of columns), .e.g.
Min:
-5
.05 quart:
-5.
.25 quart:
-1.41421
Mesn:
1.37518
Median:
2.85914
.75 quart:
3.14159
.95 quart:
4.
Max:
4
Standard Deviation: 3.07058
Unfortunately on matrices, Max[] and Min[] function behaviors are inconsistent with Mean[], Median and sd.
Min:
1
.05 quart:
{1.,3.}
.25 quart:
{3.,6.}
Mesn:
{4.49,7.41}
Median:
{4.15,7.55}
.75 quart:
{6.,8.}
.95 quart:
{9.,12.}
Max:
12
Standard Deviation: {2.3544,2.3173}
Modules
Modules are like functions but allow declaration of local variables
Arrays (like Dictionaries)
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.htm… 9/48
4/30/2017
FJ Tutorial Mathematica
Selecting from list by logical criteria: Select[list, f]
Importing and exporting data files
You can load data from a file (e.g., a csv file) or save your data to a file on your computer. For example,
You can also import data from Internet (below not right link)
System
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 10/48
4/30/2017
FJ Tutorial Mathematica
Current directory
SetDirectory[dir] changes directory to dir. To Interactively set directory:
Web Application
Create a web form where you can enter the name of any country to display its flag:
Graphics
Mathematica has very nice graphics. For example, let plot two curves in one chart: Or a threedimensional plot (that you can even rotate in the notebook using the mouse):
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 11/48
4/30/2017
FJ Tutorial Mathematica
Or, let us generate 5000 standard normal random variables and plot their histogram with 40 bins:
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 12/48
4/30/2017
FJ Tutorial Mathematica
Parametric plotting
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 13/48
4/30/2017
FJ Tutorial Mathematica
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 14/48
4/30/2017
FJ Tutorial Mathematica
Polar plot
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 15/48
4/30/2017
FJ Tutorial Mathematica
Density and contour plot
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 16/48
4/30/2017
FJ Tutorial Mathematica
Network graph
Other
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 17/48
4/30/2017
FJ Tutorial Mathematica
Playing sound
Simple Linear Regression
Regression is a big topic in statistics. Below I discuss the most basic case, which I think would suffice for your course. The simplest case is that you are given
a set of point in the xy plane and you wish to find the a line that fits these points best, i.e., has “least squared” residuals. (Instead of a line, you can also
choose a best fitting parabola or higher degree polynomial).
ListPlot[]: Plots a list of points in the plane
Let’s first define ten points on the plane, represented as a 10 by 2 matrix.
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 18/48
4/30/2017
FJ Tutorial Mathematica
We can get scatter plot of these points by using the ListPlot function
Fitting a linear model line
The Mathematica function to fit a linear model is called LinearModelFit. The second parameter, here x, says we wish to fit a line. If we wanted to fit a cubic, the
second parameter should be {x,x^2,x^3}. The third parameter (here x) is the name of the xvariable.
The output here says that the equation of the best line fit has equation y = 4.13482 + 0.729439 x, i.e., has slope 0.729439 and intercept 4.13482. There is a lot
more output available in the fitted variable model, e.g., RSquared, fitted values, residuals, variances and correlations, tstatistics, Fstatistics, pvalues, etc.
We can also use the model to “predict” what the response variable y is likely to be given x. Let’s First plot both points and the fitted lines
model[“property_name”] extracts property. To see all available properties:
Fitting a linear model cubic: LinearModelFit[]
Sometimes we might get a much better fit with a polynomial curve. (That is still a linear model because the polynomial is linear in its coefficients!!). For
example, let’s try a cubic curve:
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 19/48
4/30/2017
FJ Tutorial Mathematica
R-Squared: goodness of fit
The RSquared of the fitted model (or sometimes the adjusted Rsquared) is the primary measure of the goodness fit. RSquared is also called the
coefficient of determination. RSquared is always between 0 and 1. The closer to 1 the better the fit. In our example, the RSquared for the fitted line is
0.55, while for the cubic it is 0.83.
Predicting value
Given values for the “independent variable” x, e.g., x = 3.2, the model can be used to predict what the expected value of y would. The predicted value is
simply the y value of the predicated line (or the predicted cubic), for example for x = 3.2, it is 4.13482 + 0.729439 *3.2 = 6.46902. We get as follows:
Equations of the fitted line or curve
You can get the equations of the fitted line or the cubic also by
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 20/48
4/30/2017
FJ Tutorial Mathematica
The Residuals
The residuals are the actual y’s minus the fitted y’s. You can get them by
Advanced: t-Statistics and p-values
These are more advanced information about the model, Standard Error, tstatistics, and its pvalue. The lower the pvalue for the coefficient (intercept and
slope), the more statistically significant that value. So, a pvalue of less that 0.01 for the slope means that will 99% (or more) “confidence”, the slope is not
zero.
Estimate Standard Error t-Statistic P-Value
1 4.13482 1.17161
3.52919 0.00774118
x 0.729439 0.233626
3.12225 0.0141803
1
x
Estimate
-1.81661
6.31793
Standard Error t-Statistic P-Value
2.4542
-0.740206 0.487118
1.90173
3.3222
0.0159606
-1.35762
0.433711
0.0919748 0.0288835
-3.13025 0.020318
3.18434
0.0189715
Advanced: F-Statistics and ANOVA table
These are other advanced information about the model: Sum of squared, Mean Squared and FStatistics and the corresponding pvalues. Again, the lower
the pstatistics, the better the model fit
DF
x
1
Error 8
Total 9
SS
MS
F-Statistic P-Value
26.545 26.545 9.74846 0.0141803
21.784 2.723
48.329
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 21/48
4/30/2017
FJ Tutorial Mathematica
x
DF SS
1 26.545
MS
26.545
F-Statistic P-Value
19.6875 0.00438967
1
0.0220974 0.0220974 0.0163889 0.902317
1
13.672
13.672
8.08991
48.329
1.34832
Error 6
Total 9
10.14
0.0189715
Advanced: Confidence Intervals for the parameters
We can get 95% confidence intervals” for the parameters (and for fitted values)
Estimate Standard Error Confidence Interval
1 4.13482 1.17161
{1.43309,6.83655}
x 0.729439 0.233626
{0.190697,1.26818}
1
x
Estimate
-1.81661
6.31793
Standard Error Confidence Interval
2.4542
{-7.82183,4.1886}
1.90173
{1.66457,10.9713}
-1.35762
0.433711
0.0919748 0.0288835
{-2.41888,-0.296373}
{0.0212995,0.16265}
To get 99% confidence interval, we pass the option ConfidenceLevel→.99
Algebra
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 22/48
4/30/2017
FJ Tutorial Mathematica
Trigonometry
Regions and membership
Intervals
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 23/48
4/30/2017
FJ Tutorial Mathematica
Union and intersections also defined
Units
Inequality
Sums (and products)
Recurrence Relations
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 24/48
4/30/2017
FJ Tutorial Mathematica
Calculus
Numerical integration:
(Partial) Differentiation:
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 25/48
4/30/2017
FJ Tutorial Mathematica
Gradient
Jacobian
Integration
Integral over the disk
Numerical integration
Numerical Sum
Statistics
Hypothesis testing
Let’s extract some example data and do a test of equality of mean of two populations.
Statistic P-Value
Mann-Whitney 3801.5 4.10025*10^^-11
Distributions
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 26/48
4/30/2017
FJ Tutorial Mathematica
Clustering
Generalized linear model (Poisson)
Logistic and Probit Regression
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 27/48
4/30/2017
FJ Tutorial Mathematica
Nonlinear fit models (nonlinear least squares)
FindFit[] find the equations but does not provide the properties
Linear Algebra
Matrix (and vector) multiplication
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 28/48
4/30/2017
FJ Tutorial Mathematica
LinearSolve[A,b]
Eigenvalues
If matrix values are integer or symbolic, then exact values are calculated. If Matrix values of float, numerical values are calculated
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 29/48
4/30/2017
FJ Tutorial Mathematica
Differential Equations: DSolve[], NDSolve[]
DSolve[] finds symbolic solutions. It returns rules. NDSolve[] finds numeric. They apply to nth order ODE, ODE system and PDE
A nonlinear first order ODE,
Because below v[t] instead of v is specificity the solution is given as Rule.
A linear 4-th order ODE
Linear ODE System (with solution as function)
Instead of {x[t],y[t],v[t]}, we use {x,y,v} so the solutions are functions
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 30/48
4/30/2017
FJ Tutorial Mathematica
Nonlinear first order ODE with non-unique (two) solutions
Partial Differential Equation
First order linear PDE (homo and inhomo)
General solution involves an arbitrary function C[1]
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 31/48
4/30/2017
FJ Tutorial Mathematica
Let us choose a particular solution with C[1][t_]→Sin[t^2]+t/10
First order nonlinear PDE
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 32/48
4/30/2017
FJ Tutorial Mathematica
Second order PDE
NDSolve
Vector field plot
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 33/48
4/30/2017
FJ Tutorial Mathematica
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 34/48
4/30/2017
FJ Tutorial Mathematica
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 35/48
4/30/2017
FJ Tutorial Mathematica
Optimization
Minimization examples are given maximization is similar
Minimize[]: gives GLOBAL min point and value (MinValue[] and FindMinValue[] only give min value)
Minimize[] subject to constraint
Subject to equality constraint
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 36/48
4/30/2017
FJ Tutorial Mathematica
Integer Programming
NMinimize[] - numerical version of Minimize[]
NMinimize[] subject to constraints
Linear Programming with NMinimize[] or Minimize[]
Linear Programming
This also provides the dual solution
Optimization package
Load the optimization package for more advanced methods
FindMinimum[]: local optimization with an initial guess - one dimensional
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 37/48
4/30/2017
FJ Tutorial Mathematica
FindMinimum[] , constrained optimization
With linear and integer constraints
MultiDimensional: Newton, Quasi-Newton, Conjugate Gradient, Gauss-Newton, Principal Axis
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 38/48
4/30/2017
FJ Tutorial Mathematica
A Classical difficult problem
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 39/48
4/30/2017
FJ Tutorial Mathematica
This uses GaussNewton method for quadratic optimization
Root Finding and Fitting
Root Finding: FindRoot[]
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 40/48
4/30/2017
FJ Tutorial Mathematica
A bug of FindRoot
This was OK, but the next one is not
But, this is not a root
Root find: Solve[]. Solve[] and NSolve[] seems mostly work for polynomials
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 41/48
4/30/2017
FJ Tutorial Mathematica
FindInstance[] makes it easier to specify region
Above failed, but below works
Wolfram Alpha’s solution (and bug)
Wolfram Alpha finds no real root (which is wrong), but finds correct complex root
solve (15*t)/(1 + 3 t) - 2 - 5 Sin[4 t Pi/25] == 0
However, this version of Wolfram alpha finds solution
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 42/48
4/30/2017
FJ Tutorial Mathematica
solve (15*t)/(1 + 3 t) - 2 - 5 Sin[4 t Pi/25] = 0, 0<t<6
(15*t)/(1+3t)-2-5 Sin[4 t Pi/25]=0
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 43/48
4/30/2017
FJ Tutorial Mathematica
Solve[] works for simple trig expressions
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 44/48
4/30/2017
FJ Tutorial Mathematica
Fitting: FindFit
Fitting a vector
Fitting points: FindFit[]
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 45/48
4/30/2017
FJ Tutorial Mathematica
Linear LeastSquares[mat, b] and Fit[data, {1,x,x^2,...}]
Twodimensional function fit
Nonlinear least squares: FindFit[]
Possible settings for Method: ConjugateGradient, Gradient, LevenbergMarquard, Newton, QuasiNewton, NMinimize
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 46/48
4/30/2017
FJ Tutorial Mathematica
NonLinear Model: NonlinearFitModel[]
Produces the same result as FindFit[], but, like the model contains a lot more “properties”
Interpolation
Very basic function below. There are of course polynomials, splines, MultiDimensional interpolation, etc.
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 47/48
4/30/2017
FJ Tutorial Mathematica
Created with the Wolfram Language
file:///Users/farshid/Documents/Wolfram%20Mathematica/saved%20html/FJ%20Mathematical%20Tutorial%20html%20toc/FJ%20Tutorial%20Mathematica_toc.ht… 48/48
© Copyright 2026 Paperzz