You are on page 1of 6

Mathcad Summary

Basics
Toolbars
Equal signs: =, :=, =
Subscripts: "." vs "["
Greek letters: ctrl-g
Matrix: ctrl-m
Plot: @
Arrays start at 0, but change with ORIGIN:=1 or whatever
Evaluate: top to bottom and left to right
Units: Always work with K or R, never C, F, be careful when plotting.
Symbolic toolbar, versus symbolic menu

Integration

Define the function, then use the symbolic integral (calculus toolbar)
2
f ( x)  2x  1

1

 f ( x) dx  1.667

0

Curve Fitting
Polynomial
Use functions regress and interp

T
x  ( 0 1 2 3 4 5 )
T
y  ( 0 0.8 0.9 0.1 0.8 1 )

i  0  99
8
xp  i 2
i 99

p3  regress( x y 3 )

f ( xp)  interp( p3 x y xp)


2

0
y 2
f  xpi 4

6

8
2 0 2 4 6
x xpi

General fit
Use genfit function. Need to include partial derivatives
Fit given x, y data below to function: f ( x ) = a exp( b  x )  c

T
x  ( 0 0.41 0.82 1.22 1.63 2.04 2.44 2.86 3.26 3.67 )

T
y  ( 3.14 2.0 1.29 1.34 0.55 0.77 0.45 0.65 0.29 0.58 )

f ( x a b c)  a exp( b  x )  c

d  b xx
f ( xx a b c)  e
da

d  b xx
f ( xx a b c)  a xx e
db

d
f ( xx a b c)  1
dc

 a0 exp a1 x  a2 


 
  a1 x 
g ( x a)   e 
  a1 x 
 a0 x e 
 
 1 

2 
ag   1 
 
 0.5 
 2.677 
a  genfit( x y ag g ) a   1.251 
 
 0.441 

i  0  99
8
xp  i 2
i 99

yp  f xp a a a
0 1 2 
4

3
y
2
yp
1

0
0 1 2 3 4 5
x xp

Interpolation
Use functions linterp (for linear interplation) adn cspline for cubic splines

Define the given x, y data points, and the x_interp points to interpolate to

i  0  9
10
x  i
i 9
 ( x) 2
y  cos 
 8 

j  0  99
j  10
x_interp 
j 99
y_interp_L  linterp( x y x_interp )

cs  cspline( x y )

y_interp_S  interp( cs x y x_interp )


1

y_interp_L 0

y_interp_S

1
0 2 4 6 8 10
x x_interp x_interp

ODE System

dv 2
Solve functions: = 9.81  v
dt

dx
=v
dt

with initial condition v0 = 0 x0 = 0

0
y0   
0
9.81  y 2
D( t y )  
 0 
 y 
 0 

tstart  0 tend  3 npts  100

tvx  rkfixed ( y0 tstart tend npts D)

2
1
tvx  4
2
tvx  6
8

 10
0 1 2 3
0
tvx
System of Nonlinear Equations
Functions: root, polyroots, Given/Find block
Find a solution to the following two equations for y, z
3 2
y = z  3z  5z  3

z = z  10

y  1.0

z  1.0

Given

3 2
y = z  3z  5z  3

y = z  10

 y   Find( y z)
 
z 

y  12.516

z  2.516

System of Linear Equations


Find solution x for system Ax=b
 1 2 3 
A  4 5 6
 
7 8 9
0 
b   1 
 
 1 

x  lsolve( A b ) or 1
x  A b

 2.875 
x   0.75 
 
 1.458 

You might also like