Curve Fit Equations
A curvefit equation is written as a 'C-style' formula.
Some examples
| What you want | What you type | Variables in the equation |
|---|---|---|
| mx+b | m*x+b | m, b |
| Ax2 | A*x**2 | A |
| Ae-x2 | A*exp(-x**2) | A |
| Asin(ωt-kx+φ) | A*sin(\omega*t-k*x+\phi) | A, \omega, \phi |
| tan(2π/180 x) | tan(2*\pi/180*x) | None. π is a constant here. |
Some basic rules
- Don't write the 'y =' part. For y = m*x+b, just write the m*x+b part
- The variable you are fitting to (whatever is on the x-axis) is always called 'x'
- Any other variables have to be created in the curve fit dialog (see curve fit help for more information).
- You have to write out all the multiplication symbols.
- Multiplication is written as a '*'
mx+bneeds to be written asm*x+b
- Exponents are written with '**'
- x2 is written as x**2
- Functions like sin x and tan x are written as: sin(x) and tan(x)
- exp(x) returns ex. log(x) returns the natural logarithm of x (base e). log10(x) returns the logarithm of x in base 10.
- You can pi to represent π (3.14159....).
- Angles are given in radians. If your data is in degrees, then convert to radians like this: sin(2*pi/180*x)
- If you want a variable named for a greek letter, write it as \greek_letter. Eg For λ, write \lambda. For capital greek letters, just capitalize it: for Λ, write \Lambda. In curve-fit formulas, you can write \pi to get it to show up as π. In column formulas you must leave it as pi.
Order of operations
Order of operations is like in C, BASIC, Fortran or almost any other programming language. If you aren't sure, just throw in some parentheses. The following table shows the order of operations from highest precedence to least precedence:
| Operator | Example | Explanation | |
|---|---|---|---|
| highest | () | (x*2) | parentheses |
| precedence | ** | a**b | exponentiation |
| * | a*b | multiplication | |
| / | a/b | division | |
| % | a%b | modulo | |
| lowest | + | a+b | addition |
| precedence | - | a-b | subtraction |
You can use other c-like operators such as ==, <=, && or ||.
Functions
| Function | Explanation |
|---|---|
| abs(x) | absolute value of x, |x| |
| acos(x) | inverse cosine in radians |
| asin(x) | inverse sin in radians |
| atan(x) | inverse tangent in radians |
| besj0(x) | j_0 Bessel function of x* |
| besj1(x) | j_1 Bessel function of x* |
| besy0(x) | y_0 Bessel function of x* |
| besy1(x) | y_1 Bessel function of x* |
| ceil(x) | smallest integer not less than x (real part) |
| cos(x) | cosine of x* |
| cosh(x) | hyperbolic cosine of x* |
| erf(x) | error function of x |
| erfc(x) | 1.0 - error function of x |
| exp(x) | exponential function of x |
| floor(x) | largest integer not greater than x |
| gamma(x) | gamma function of x |
| int(x) | integer part of x, truncated toward zero |
| log(x) | natural logarithm (base e) of x |
| log10(x) | logarithm (base 10) of x |
| rand(x) | pseudo random number generator |
| sgn(x) | 1 if x > 0, -1 if x < 0, 0 if x = 0. |
| sin(x) | sine of x* |
| sinh(x) | hyperbolic sine x* |
| sqrt(x) | square root of x (use x**(1/n) to get the nth root of x). |
| tan(x) | tangent of x* |
| tanh(x) | hyperbolic tangent of x* |
*Angles are given in radians. If your data is in degrees, then convert to radians like this: sin(2*pi/180*x)
