0% found this document useful (0 votes)
101 views23 pages

An Introduction To MATHEMATICA PDF

This document provides an introduction and overview of the Mathematica software. It outlines the basics of Mathematica including syntax, arithmetic, algebra, calculus, differential equations, programming constructs, and plotting capabilities. The document was presented at a national workshop on computational methods in engineering and mathematics using MATLAB and Mathematica.

Uploaded by

Miguel Herrera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views23 pages

An Introduction To MATHEMATICA PDF

This document provides an introduction and overview of the Mathematica software. It outlines the basics of Mathematica including syntax, arithmetic, algebra, calculus, differential equations, programming constructs, and plotting capabilities. The document was presented at a national workshop on computational methods in engineering and mathematics using MATLAB and Mathematica.

Uploaded by

Miguel Herrera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

An Introduction to MATHEMATICA

Srinivasarao Thota
Assistant Professor in Mathematics

Department of Applied Sciences


Shoolini University
Solan, India

National Workshop
on
Computational Methods in Engineering and Mathematics using
MATLAB and MATHEMATICA
(Marudhar Engineering College, Bikaner)

19-20 April, 2013

S.Thota () MATHEMATICA National Workshop 1 / 23


Outline

1 Introduction
2 Syntax and Grammar
3 Basic Calculations (Algebra)
4 Solving Equations
5 Basic Calculations (Calculus)
6 Differential Equations
7 Control Structures
8 A Simple Program
9 Some selected toolboxes

S.Thota () MATHEMATICA National Workshop 2 / 23


Introduction

1 It has been developed by prof. Stephen Wolfram and is now being


developed and distributed by Wolfram Research Inc.
2 A system for doing mathematics by computer.
3 Also for modelling, simulation, visualization, development,
documentation, and deployment.
4 Initial release 1988 and Current version: 9 (Jan, 2013)
5 Versions for: Windows XP, Vista Mac OS-X, Unix/Linux.

S.Thota () MATHEMATICA National Workshop 3 / 23


Syntax and Grammar
Arithmetic

1 Addition : 2+2
2 Subtraction : 4-1
3 Multiplication : 3∗2 and also : 3 2
4 Division : 15/2
5 Exponentiation : 42
6 Factorial : 4!

S.Thota () MATHEMATICA National Workshop 4 / 23


Grammar

1 a list : {1, 2, 3, 4}
2 a function : f [x, y ]
3 a list element : v [[1]]
4 parentheses for grouping : 2 ∗ (3 + 5)
5 a rule : x− > 5
6 a definition : f [x− ] := 2x + 5
7 an assignment : x = 42

S.Thota () MATHEMATICA National Workshop 5 / 23


Advanced Function Shorthand
1 Postfix : x//f
2 Replace All : (x 2 + 3x) /. x− > (a + b)
3 Map : Factorial /@ {1, 2, 3}

Lists
1 A 3-vector : v = {1, 4, 2}
2 A 2 × 2 matrix : m = {{1, 2}, {3, 4}}

Create a list
1 Range[10]
2 Array[Factorial, 6]
3 Table[x 2 , {x, 4, 12}]

S.Thota () MATHEMATICA National Workshop 6 / 23


Some list operations
1 mylist = Range[13]
2 Drop[mylist, 3]
3 Take[mylist, 3]
4 Append[mylist, 3]
5 Prepend[mylist, 3]
6 Partition[mylist, 3]

S.Thota () MATHEMATICA National Workshop 7 / 23


Basic Calculations (Algebra)

Define a polynomial expression


poly = (1 − x 2 )(2 + 3x)

Perform some manipulations


1 Expand[poly]
2 Factor[poly]
3 solns = Solve[poly == 0, x]
4 poly /.x− > 2
5 poly /. solns[[1]]
6 Coefficient[Expand[poly], x 2 ]

S.Thota () MATHEMATICA National Workshop 8 / 23


Solving equations:

1 Solve[x 2 == 1, x]
2 Solve[{x + 2y == 3, 2x − y == 5}, {x, y }]
3 Solve[{x + 2y == 3, 2x − y == 5}, x, y ]
4 Solve[2x 2 == 3, x]
5 NSolve[2x 2 == 3, x]
6 FindRoot[2x 2 == 3, {x, 3}]
7 Solve[2x 2 == 3 && 5x + 1 == 2, x]

S.Thota () MATHEMATICA National Workshop 9 / 23


Calculus

An expression
expr = 2 + 3x + x 2 − Log [x]

Differentiation
1 D[expr, x]
2 D[expr, x, x]

Integration
1 Integrate[expr, x]
2 Integrate[expr, {x, 0, 1}]
3 NIntegrate[expr,{x, 0, 1}]

S.Thota () MATHEMATICA National Workshop 10 / 23


Differential Equations

1 The derivative of an unknown function, y , can be represented by: y 0 .


2 DSolve[y 0 [x] + y [x] == 1, y [x], x]

For functional representation of y


DSolve[y 0 [x] + y [x] == 1, y , x]

Numerical methods
NDSolve[{y 0 [x] == y [x], y [0] == 1}, y , {x, 0, 2}]

S.Thota () MATHEMATICA National Workshop 11 / 23


Other Common Tasks

1 Limit[Sin[x]/x, x− > 0]
2 Limit[1/x, x− > 0, Direction− > 1]
3 Residue[1/x, {x, 0}]
4 ConstrainedMax[x − y , {x < 2y , x < 4}, {x, y }]
5 ConstrainedMin[x − y , {x > 3y , x > 2}, {x, y }]
6 mat = {{1, 2}, {3, 4}}
7 Det[mat]
8 Eigenvalues[mat]
9 Eigenvectors[mat]

S.Thota () MATHEMATICA National Workshop 12 / 23


Control Structures

1 Do [expression, iterator, min, max ]


* Do[Print[i!], {i, 2, 10}]
2 For [ init-expr, test-expr, iterate-expr, body-expr ]
* For[i = 2, i < 10, i + +, Print[i!]]
3 If [ test-expr, if-true, if-false, if-neither ]
* abs[x− ] := If [x < 0, −x, x, ”x isn’t a number”]
4 Which[test, value, test, value, . . . ]
* signum[x− ] := Which[x < 0, −1, x > 0, 1, True, 0]

S.Thota () MATHEMATICA National Workshop 13 / 23


A Simple Program

multitable[num− ] :=
Module[{i},
Print[num ”multiplication table”];
For [i = 0, i < 10, i + +
Print[num∗i];
];
];

S.Thota () MATHEMATICA National Workshop 14 / 23


ODEs
Separable Equations
The general solution to this equation is found by separation of variables.

DSolve[y’[x] == (x 2 y [x]2 )/Sqrt[3 − x 2 ], y, x]

Homogeneous Equations
A homogeneous equation

eqn = y’[x] == -(x 2 − 3y [x]2 )/(x*y[x]);


sol = DSolve[eqn, y, x]

Linear First-Order Equations


A linear first-order ODE
sol = DSolve[y’[x] + y[x] == Q[x], y[x], x]

S.Thota () MATHEMATICA National Workshop 15 / 23


Bernoulli Equations
A Bernoulli equation is a first-order equation of the form
y 0 (x) + p(x)y (x) = Q(x)y (x)n .

eqn = y’[x] + 11 x*y[x] == x 3 ∗ y [x]3


sol = DSolve[eqn, y, x]

Exact Equations
P[x− , y− ] := -(5x 2 − 2y 2 + 11)
Q[x− , y− ] := (Sin[y] + 4 x*y + 3)
Simplify[D[P[x, y], y] - D[Q[x, y], x]]
eqn = y’[x] == -P[x, y[x]]/Q[x, y[x]]
sol = DSolve[eqn, y[x], x]

S.Thota () MATHEMATICA National Workshop 16 / 23


DSolve

DEs solving with DSolve


1 First-Order ODEs
2 Linear Second-Order ODEs
3 Nonlinear Second-Order ODEs
4 Higher-Order ODEs
5 Systems of ODEs
6 Nonlinear ODEs with Lie Symmetries

S.Thota () MATHEMATICA National Workshop 17 / 23


System of ODEs

Linear Systems of ODEs


X[t− ] = {x[t], y [t]};
A = {{4, −6}, {1, −1}};
system = X’[t] == A.X[t];
sol = DSolve[system, {x, y }, t]

Nonlinear Systems of ODEs


system = {p’[x] == 1, q’[x] == x, r’[x] == 0, s’[x] == r[x]/(p[x] +
4*q[x]*r[x])};
sol = DSolve[system, {p, q, r, s}, x]

S.Thota () MATHEMATICA National Workshop 18 / 23


Partial Differential Equations

Linear homogeneous first-order PDE


z := u[x, y]
p := D[u[x, y], x]
q := D[u[x, y], y]
eqn = 2*p + 3*q + z == 0;
sol = DSolve[eqn, u, x, y]

Linear homogeneous PDE with variable coefficients


eqn = Sin[x]*p + E ∧ x ∗ q == 0;
sol = DSolve[eqn, u, x, y]

S.Thota () MATHEMATICA National Workshop 19 / 23


Matrix Operations
1 Dot(.)-products of matrices, automatically handling row and column
vectors
2 Inverse-matrix inverse
3 Transpose-transpose
4 ConjugateTranspose-conjugate transpose
5 Tr-trace
6 Det-determinant
7 KroneckerProduct-matrix direct product (outer product)
8 MatrixExp-matrix exponential
9 MatrixFunction-general matrix function
10 Eigenvalues, Eigenvectors-exact or approximate eigenvalues and
eigenvectors
11 Eigensystem-eigenvalues and eigenvectors together
12 CharacteristicPolynomial-symbolic characteristic polynomial
S.Thota () MATHEMATICA National Workshop 20 / 23
Plotting Graphs

Plot: Basic Example


Plot[Sin[x], {x, 0, 6Pi}]
Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi}]
Plot[2 Sin[x] + x, {x, 0, 15}, Filling − > Bottom]
Plot[{Sin[x] + x/2, Sin[x] + x}, {x, 0, 10}, Filling − > {1− > {2}}]

Plot3D: Basic Example


Plot3D[Sin[x + y 2 ], {x, −3, 3}, {y , −2, 2}]
Plot3D[{x 2 + y 2 , −x 2 − y 2 }, {x, −2, 2}, {y , −2, 2}, ColorFunction− >
”RustTones”]

S.Thota () MATHEMATICA National Workshop 21 / 23


For more details
http://www.wolfram.com/training/

S.Thota () MATHEMATICA National Workshop 22 / 23


THANK YOU

S.Thota () MATHEMATICA National Workshop 23 / 23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy