ph36010 numerical methods some more useful functions in mathcad

14
PH36010 PH36010 Numerical Methods Numerical Methods Some more useful functions in Some more useful functions in MathCAD MathCAD

Upload: jesse-ellis

Post on 02-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: PH36010 Numerical Methods Some more useful functions in MathCAD

PH36010 PH36010 Numerical MethodsNumerical Methods

Some more useful functions in Some more useful functions in MathCADMathCAD

Page 2: PH36010 Numerical Methods Some more useful functions in MathCAD

Piecewise continuous functionsPiecewise continuous functions

• So far, functions have been So far, functions have been continuous & ‘smooth’continuous & ‘smooth’

• Real world has ‘abrupt’ changesReal world has ‘abrupt’ changes• MathCAD has functions which can MathCAD has functions which can

model these changesmodel these changes

Page 3: PH36010 Numerical Methods Some more useful functions in MathCAD

Abrupt changes in the real Abrupt changes in the real worldworld

• The impulse given by a hammer.The impulse given by a hammer.• The magnetic field due to a current in a The magnetic field due to a current in a

circular conductor has different equation circular conductor has different equation inside and outside of the conductor.inside and outside of the conductor.

• A rocket motor produces a constant A rocket motor produces a constant thrust until the fuel runs out, then it thrust until the fuel runs out, then it produces zero thrust.produces zero thrust.

• A potential well has abrupt changes in A potential well has abrupt changes in potential at its edges.potential at its edges.

Page 4: PH36010 Numerical Methods Some more useful functions in MathCAD

The if() functionThe if() function

• 3 arguments3 arguments• 1 boolean expression (condition)1 boolean expression (condition)• ‘‘True’ valueTrue’ value• ‘‘False’ valueFalse’ value• Condition evaluatedCondition evaluated• if ‘true’ (non-zero) return true value if ‘true’ (non-zero) return true value

else return false valueelse return false value

Page 5: PH36010 Numerical Methods Some more useful functions in MathCAD

Boolean ExpressionsBoolean Expressions

• Use relation operators (evaluation Use relation operators (evaluation palette)palette)=,>,<,=,>,<,,,,,

• True=1 (anything non-zero)True=1 (anything non-zero)• False=0False=0• Can use multiply & add for Can use multiply & add for

AND/ORAND/OR

Page 6: PH36010 Numerical Methods Some more useful functions in MathCAD

Examples of if()Examples of if()

if 1 0 999 42( ) 999

if 5 6 1( ) 1

Page 7: PH36010 Numerical Methods Some more useful functions in MathCAD

Magnetic field due to wire Magnetic field due to wire #1#1

B 0 I

2 R

B 0 I R

2 a2

BWire R( ) 0 I test

2 if R a

1

R

R

a2

Field outside wire (R>a)Field outside wire (R>a)

Field inside wire (R<a)Field inside wire (R<a)

Extract common terms & combine Extract common terms & combine with if()with if()

Page 8: PH36010 Numerical Methods Some more useful functions in MathCAD

Magnetic field due to wire Magnetic field due to wire #2#2

I test 2 A

0 2 4 6 8 100

1 10 4

2 10 4

BWire R( )

a

mm

R

mm

Page 9: PH36010 Numerical Methods Some more useful functions in MathCAD

The Kronecker delta The Kronecker delta function: function: (x,y)(x,y)

• Provides an impulse. Provides an impulse. • Returns 1 if x=y, 0 otherwiseReturns 1 if x=y, 0 otherwise• Equivalent to if(x=y,1,0)Equivalent to if(x=y,1,0)

x 10 9.8 10 .

0 2 4 6 8 101

0

1

x 2( )

x

Page 10: PH36010 Numerical Methods Some more useful functions in MathCAD

Heavyside Step function Heavyside Step function (x)(x)

• Provides a step at x=0Provides a step at x=0• Equivalent to if(x>0,1,0)Equivalent to if(x>0,1,0)

10 5 0 5 100

1

22

0

x 1( )

1010 x

Page 11: PH36010 Numerical Methods Some more useful functions in MathCAD

Combining Combining (x) to form (x) to form pulsespulses

t1 1 t2 3

pulse x( ) x t1( ) t2 x( )

0 2 4 6 8 100

1

2

pulse x( )

t1 t2

x

Page 12: PH36010 Numerical Methods Some more useful functions in MathCAD

Truncation Truncation floor(), ceil(), trunc()floor(), ceil(), trunc()

• All functions take real & convert to All functions take real & convert to integerinteger

• trunc trunc 0 0• floor floor - -• ceil ceil

trunc 3.1( ) 3 trunc 3.9( ) 3 trunc 3.1( ) 3 trunc 3.9( ) 3

floor 3.1( ) 3 floor 3.9( ) 3 floor 3.1( ) 4 floor 3.9( ) 4

ceil 3.1( ) 4 ceil 3.9( ) 4 ceil 3.1( ) 3 ceil 3.9( ) 3

Page 13: PH36010 Numerical Methods Some more useful functions in MathCAD

Random NumbersRandom Numbers

• Useful for:Useful for:– Modelling statistical processesModelling statistical processes– Monte Carlo simulationMonte Carlo simulation

• 2 methods of generation:2 methods of generation:– rnd(x) – returns 1 number in range rnd(x) – returns 1 number in range

0<x (Uniform distribution)0<x (Uniform distribution)– All others return vector of numbers All others return vector of numbers

with specified distributionwith specified distribution

Page 14: PH36010 Numerical Methods Some more useful functions in MathCAD

Random NumbersRandom Numbers

• Lottery Predictor (!!)Lottery Predictor (!!)NBalls 6 MaxNum 42

i 0 NBalls 1

Drawi trunc rnd 42( )( ) 1

DrawT

13 29 18 6 20 3( )

• Needs workNeeds work• Duplicate numbersDuplicate numbers• Not guaranteedNot guaranteed