Showing posts with label parametric. Show all posts
Showing posts with label parametric. Show all posts

Friday, September 1, 2017

TI-84 Plus CE: Fitting Points to an Ellipse

TI-84 Plus CE: Fitting Points to an Ellipse

Back to one of my favorite subjects: curve fitting.



The program ELLIPFIT attempts to fit a parametric curve for a collection of points (x, y) to an ellipse using the following equations:

x = a * cos t + b
y = c * sin t + d

where the independent variable is t.  The program also plots the estimated line and the scatter plot.  I decided to keep the correlation (r^2) separate, so we can tell how well the line fits both the x and y data. 

The program uses the range of 0 ≤ t ≤ 2*π, where t is in radians.

The user is asked to provide two lists, x and y.   The list of t values is determined by the atan2, angle, or arg function of the complex number point x + y*i.  The angle is adjusted to the range of [0, 2*π].

Quadrant I: x ≥ 0, y ≥ 0, angle(x + y*i)
Quadrant II: x < 0, y ≥ 0, angle(x + y*i)
Quadrant III: x < 0, y < 0, angle(x + y*i) + 2*π
Quadrant IV: x ≥ 0, y < 0, angle(x + y*i) + 2*π

TI-84 Plus CE Program ELLIPFIT

Notes:

L1: list 1, [ 2nd ] [ 1 ]; L2: list 2, [ 2nd ] [ 2 ], etc.  X1T, Y1T are from the [ vars ], Y-VARS, Parametric submenu

[square] is from [2nd] [ y= ] (stat plot) , MARK submenu, option 1

The complex variable i = √-1 is found by pressing [ 2nd ] [ . ].

Program:

"ELLIPTICAL FIT"
"2017-08-31 EWS"
Param:Radian:a+bi
Input "X LIST: ",L2
Input "Y LIST: ",L3
FnOff
L2→L1
For(I,1,dim(L1))
angle(L2(I)+L3(I)*i)→T
If L3(I)<0
Then
T+2π→T
End
T→L1(I)
End
PlotsOff
cos(L1)→L4
LinReg(ax+b) L4,L2
a→A:b→B:r²→E
"Acos(T)+B"→X1T
ClrHome
Disp "X = A*cos(T)+B"
Disp A
Disp B
Disp "CORR: "
Pause E
sin(L1)→L4
LinReg(ax+b) L4,L3
a→C:b→D:r²→F
"Csin(T)+D"→Y1T
ClrHome
Disp "Y = C*sin(T)+D"
Disp C
Disp D
Disp "CORR: "
Pause F
FnOn 1
PlotsOn 1
GraphColor(1,RED)
Plot1(Scatter,L2,L3,[square],GREEN)
0→Tmin
2π→Tmax
ZoomStat

(Obviously use the colors and makers you like.   If you are working with a monochrome TI-83/TI-84, ignore the color commands.)

You can get a download here:

Example 1

A perfect circle:

X
Y
0
1
1
0
0
-1
-1
0

Results:
x = cos t (r^2 = 1)
y = sin t (r^2 = 1)




Example 2

X
Y
1.0
0.0
0.5
0.5
0.0
1.0
-0.5
0.5
-1.0
0.0
-0.5
-0.5
0.0
-1.0
0.5
-0.5

Results:
x = 0.8535533906 cos t (r^2  ≈ 0.97140)
y = 0.8535533906 sin t  (r^2 ≈ 0.97140)

 


Eddie


This blog is property of Edward Shore, 2017.

Wednesday, August 30, 2017

TI-84 Plus CE: Fitting a Parametric Line

TI-84 Plus CE:  Fitting a Parametric Line

The program PARLIN attempts to fit a parametric line for a collection of points (x(t), y(t)) using the following equations:

x = a * t + b
y = c * t + d

where the independent variable is t.  The program also plots the estimated line and the scatter plot.  I decided to keep the correlation (r^2) separate, so we can tell how well the line fits both the x and y data. 

TI-84 Plus CE Program PARAM

Notes:

L1: list 1, [ 2nd ] [ 1 ]; L2: list 2, [ 2nd ] [ 2 ], etc.  X1T, Y1T are from the [ vars ], Y-VARS, Parametric submenu

[square] is from [2nd] [ y= ] (stat plot) , MARK submenu, option 1

Program:

Param
Input "T LIST: ",L1
Input "X LIST: ",L2
Input "Y LIST: ",L3
FnOff
PlotsOff
LinReg(ax+b) L1,L2
a→A:b→B:r²→E
"AT+B"→X1T
ClrHome
Disp "X = A*T + B"
Disp A
Disp B
Disp "CORR: "
Pause E
LinReg(ax+b) L1,L3
a→C:b→D:r²→F
"CT+D"→Y1T
ClrHome
Disp "Y = C*T + D"
Disp C
Disp D
Disp "CORR: "
Pause F
min(L1)-5→Tmin
max(L1)+5→Tmax
FnOn 1
PlotsOn 1
GraphColor(1,BLUE)
Plot1(Scatter,L2,L3, [square] ,ORANGE)
ZoomStat

(Obviously use the colors and makers you like.   If you are working with a monochrome TI-83/TI-84, ignore the color commands.)

You can also download the program here:


Example 1

Fit the data to a parametric line:

T
X
Y
1
2.3
-3.0
2
2.8
-2.6
3
3.2
-2.3
4
3.7
-1.9
5
4.2
-1.6

Results:  
x = 0.47*t + 1.83 (r^2 ≈ 0.998)
y = 0.35*t – 3.33 (r^2 ≈ 0.997)




Example 2

Fit the data to a parametric line:

T
X
Y
1
-1.0
1.000
2
1.0
1.250
4
5.3
1.746
8
13.6
2.825
16
30.1
4.275

Results:
x = 2.075268817 * t – 3.066666667 (r^2 ≈ 0.99997)
y = 0.2196827957* t + 0.857166667 (r^2 ≈ 0.99145)



Eddie


This blog is property of Edward Shore, 2017.

Tuesday, March 6, 2012

Spirals


All About Spirals

This blog will about spirals. Why? I thought it would be fun. And I like spirals.


Regular Spirals

Source: http://www.mathematische-basteleien.de/spiral.htm

Equations:
Rectangular
x^2 + y^2 = a^2 (arctan y/x)^2

Polar
r = a θ

Parametric
x = a t cos t
y = a t sin t


Finding the y-intercept and x-intercept, as shown above, of a spiral, assuming 0 ≤ θ ≤ 2 π

We can use the rectangular equation to find these points.

x^2 + y^2 = a^2 (arctan y/x)^2

Y-Intercept - Point (0, y)

y^2 = a^2 (arctan y/0)^2

Note:
1. y/0 is undefined
2. tan (π /2) is undefined. So is tan (n π / 2) where n is an integer.

Use π / 2 as a solution.

Then:

y^2 = a^2 * (π / 2)^2

Take the square root of both sides, since y>0, use the positive root.

y = a * π / 2

The y-intercept is (0, a * π / 2)

X-Intercept - Point (x, 0)

x^2 = a^2 (arctan 0)^2

Note tan(n π.)=0 where n is an integer. Let's use π. (n = 1)

x^2 = a^2 π^2

Since the x-intercept lies left of 0, select the negative square roof. Therefore:

x = -a π.

The x-intercept is (-a π, 0).

Area of a Spiral (0 ≤ θ ≤ 2 π)

Use the polar equation: r = a θ

Using the general polar integral:

A = ∫ (1/2 * r^2 d θ , lower limit, upper limit)

A = ∫ (1/2 * a^2 * θ^2 d θ , 0, 2 π)
= a^2 / 2 * (8 π^3 / 3 - 0)
= 4 a^2 π^3 / 3

Slope of a Spiral

Polar Form:

∂r/∂θ = a

Parametric Form:

∂x/∂t = ∂/∂t (a * t * cos t)
= ∂/∂t (a * t) * cos t + a * t * ∂/∂t (cos t)
= a * cos t - a * t * sin t
= a * (cos t - t * sin t)

∂y/∂t = ∂/∂t (a * t * sin t)
= ∂/∂t (a * t) * sin t + a * t * ∂/∂t (sin t)
= a * sin t + a * t * cos t
= a * (sin t + t * cos t)

Stretch Spirals

What if we can "stretch" spirals? We can if alter the parameters of the parametric form:

x(t) = a * t * cos t
y(t) = b * t * sin t

Where a ≠ b.

Two graphical examples are shown below.


Finding the Intercepts of a Stretched Spiral

I will assume that both a ≠ 0 and b ≠ 0.

Y-Intercept: Point (0, y)

0 = a * t * cos t
y = b * t * sin t

Working with the first equation:

0 = a * t * cos t
0 = t * cos t,

which implies that either t = 0 or cos t = 0

We know that cos (n π / 2) = 0 where n is an integer. Choose t = π / 2.

Then y = b * π / 2 * sin(π / 2) = b * π / 2

Then the y-intercept is (0, π / 2).

X-Intercept: Point (x, 0)

x = a * t * cos t
0 = b * t * sin t

Working with the second equation:
0 = b * t * sin t
0 = t * sin t

which implies that t = 0 or sin t = 0. We know that sin(n π) = 0 where n is an integer, let's choose n = 1 and then t = π.

Hence x = a * π * cos π = -a * π.

The x-intercept is (-a * π, 0)

Area of a Stretched Spiral

We can find the area using the following:

∫ y dx = ∫ y(t) d[x(t)]

Note that:
1. y(t) = b * t * sin t
2. d[x(t)] = a * (cos t - t * sin t) dt
3. y(t) d[x(t)] = a * b * (t * sin t * cos t - t^2 * sin^2 t)

Let Φ = (t * sin t * cos t - t^2 * sin^2 t)

The integration is split into two intervals: [0, π] and [π, 2 π]. Due to the direction of the spiral, the limits are switched.

Then the area is:
A = a * b * ( ∫ (Φ dt, π , 0 ) + ∫ ( Φ dt, 2 π , π ) )
(via Hewlett Packard HP 50g and TI nSpire CX CAS)
= a * b * (π^3 / 6 + 7 * π^3 / 6)
= a * b * (4 π / 3)

Slope of a Stretched Spiral

The derivation is similar to the slope of a regular spiral.

∂x / ∂t = a * ( cos t - t * sin t )
∂y / ∂t = b * ( sin t + t * cos t )


Until next time, Eddie.



This blog is property of Edward Shore. (c) 2012

Wednesday, February 22, 2012

An Approach to Plotting Functions in the Complex Plane using Parametric Mode

Graphing functions on the complex plane is not easily handled on a graphing calculator. Few options exist: (1) build a program to build an x-list and a y-list and build a Scatterplot, and (2) use the parametric graphing mode using a numerous amount of paths.

All screen shots are taken with an iPad 2 and a TI nSpire CX CAS calculator.

The complex plane is shown below:

There are pros and cons to each method. The pro of method (1) is that you would get a complete picture of any desired mesh. However, you are also faced with high execution time, even on the best graphing calculators, a lot of RAM usage, and you can usually only use a small area to graph on: for example the interval [-2,2] with 25 point intervals.

Method (2) involves parametric graphing that splits the function into two parts: the real component x(t), and its imaginary component y(t). For any complex function f(z):

x(t) = real(f(z))
y(t) = imag(f(z))

You will either have to separate the real and imaginary components, or if you graphing calculator can handle complex operations, use the real and imag functions.

Caution: If you calcualtor can handle complex numbers, some may not have a built in routine for the trigonometric or advanced operations. This applies to the TI-84 family, and most (if not all) Casio graphing calculators. I list some advanced operations for convenience.

Source: HP-41C Math Pac, Hewlett Packard, 1980?


Let z = x + yi, r = abs(z), θ = arg(z) = angle(z), i = √ -1

ln z = ln r + θ i
a ^ z = e ^ (z ln a)
sin z = sin x cosh y + i cos x sinh y
cos z = cos x cosh y - i sin x sinh y
z ^ n = r ^ n * e ^ ( i n θ )
z ^ ( 1/n ) = r ^ ( 1/n ) * e ^ ( i ( θ / n + ( 2 π k ) / n ) ) , k = 0, 1,...,n - 1
e ^ z = e ^ x * cos y + i * e ^ x * sin y


There is one big obstacle with using the parametric mode. There is only one independent variable, t. So using a set of parametric equations describe only one path.

For example, in graphing sin z set the pair of parametric equations as:
x(t) = real(sin(t + t i))
y(t) = imag(sin(t + t i))

graphs sin z along the path y = x. (x=t, y=t)

In order to get a more complete picture (or really, just more detail), you will have to repeat the pair, but using different paths.


Examples:
For path y = x, use t + t i (sub x = t, y = t)
For path y = -x, use t - t i (sub x = t, y = -t)
For path y = 2x, use 2t + t i (sub x = t, y = 2t)
For path y = e^x, use e^t + t i (sub x = t, y = e^t)
For path y = ln x, use t + e^t * i (sub x = e^t, y = t)
For path y = x^n, use t + t^n * i (sub x = t, y = t^n)
For path y^n = x, use t^n + t * i (sub x = t^n, y = t)


This method is good if you don't want to program, just want to get a quicker picture (method (2) still takes a lot of effort), or you are working with a monochromatic screen (most graphing calculators) where too much detail can just "paint the screen black".

Below are examples of graphs of complex functions from the use of method (2). Keep in mind that these are not complete graphs but enough to get some idea of what is going on.

Hope you enjoyed this blog. Eddie



This blog is property of Edward Shore. © 2012

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...