Monday, July 30, 2012

Applications and Programming: Area of a Polygon Given the Coordinates of Vertices

Today's blog entry is how to find the area of an enclosed polygon, when you just know the vertices (corner points) of the polygon.

The area, with n vertices, is:

A ≈ 1/2 * | (x1 y0 - x0 y1) + (x2 y1 - x1 y2) + (x3 y2 - x2 y3) + ... + (x0 yn - xn y0) |

With | | representing the absolute value.

The sum ends with the last vertex of the set and the initial vertex. The calculation is a fairly simple one.

The following TI-84+ program handles this formula.

TI-84+ Program AREAVERT

: Input "X0:",X
: Input "Y0:",Y
: {X} → L1
: {Y} → L2
: 0 → T
: 1 → K
: Lbl Y
: 1+K→ K
: Input "NEXT X:", A
: Input "NEXT Y:", B
: augment(L1,{A})→ L1
: augment(L2,{B})→ L2
: T+A*L2(K-1)-B*L1(K-1)→ T
: Menu("MORE?","YES",Y,"NO",N)
: Lbl N
: T+X*L2(K)-Y*L1(K)→ T
: abs(T)/2→ T
: Disp "AREA=", T
: Pause


Notes:
* L1 is accessed by pressing [2nd], [ 1 ]
* L2 is accessed by pressing [2nd], [ 2 ]
* The program works best if you start with one vertex and cycle either clockwise or counterclockwise, and stay in one direction all the way through.
* The program will ask you if there are more vertices. You do not have to repeat the initial vertex in is program.

Example 1:

Find the area of a square with the vertices (0,0), (0,5), (5,5), and (5,0). This is a square with a side length of 5 units.

Area: 25.

Example 2:

Find the area of a polygon with vertices (-3,0), (3,0), (4,11), (2,15), and (-4,12).

Area: 95.5


Until next time,
Eddie

This blog is property of Edward Shore. © 2012

Friday, July 27, 2012

Deal or No Deal (TI-84+)

Deal or No Deal?

This blog entry is about the famous game show Deal or No Deal?. The object is to win as much money as possible by either picking the grand prize or selling your box to the banker for more than what it's worth.

Deal or No Deal? has been broadcasted all over the world. Currently, there are several versions airing today. The Great Britain version is hosted by Noel Edmonds, while in Australia the host is Andrew O'Keefe. The UK version (which is presented in TI-84+ program today), offers a top prize of £250,000 (British pounds). The Australia version offers a top prize of 200,000 Australian dollars (not the same as US dollars). The Australia version also offers a car. In Egypt, the show is called Lebet El Hayat, hosted by Razan Maghrebi, where the top prize is 1,000,000 EGP (Egyptian pounds). Versions air in the Philippines, Panama, Spain, Chile, China, and India, just to name a few.

The version that aired in the United States, which aired from 2005 to 2009 (a syndicated version aired from 2008 to 2010), was hosted by Howie Mandel. The U.S. version offered a top prize of $1,000,000. The U.S. version did not last as long as it suffered from spoilers, overdrawn segments, and unnecessary fluff during games.

My favorite current version is the UK version. The game is well paced with the right amount of drama.

The program presented here uses the UK boards. A pence is a British penny, 100 pence is a British pound. Here is the board (22 boxes):


1p (0.01)
10p (0.10)
50p (0.50)
£1
£5
£10
£50
£100
£250
£500
£750


£1,000
£3,000
£5,000
£10,000
£15,000
£20,000
£35,000
£50,000
£75,000
£100,000
£250,000


UK DEAL OR NO DEAL
TI-84+


Program DEALGAME
: seq(X,X,1,22)→ L1
: randIntNoRep(1,22)→ L2
: {.01, .1, .5, 1, 5, 10, 50, 100, 250, 500, 750, 1000, 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000, 250000} → L3
: Disp "TOP PRIZE:", max(L3)
: Input "PICK YOUR BOX:", Y
: 0 → L1
: L3(L2(Y)) → Z
: {5,3,3,3,3,3}→ L4
: For(R, 1, 6)
: L4(R) → I
: For(K,I,1,-1)
: Disp "BOXES TO GO:", K
: Pause L1
: Input "CHOICE:", C
: 0→ L1(C)
: L3(L2(C))→ E
: Disp "AMOUNT:",E
: Pause
: D-1→ D
: 0→ L3(L2(C))
: End
: Disp "BOARD:"
: Pause L3
: Disp "TOP DOLLAR:", max(L3)
: Disp "BANKER'S OFFER..."
: round((rand/2+.5)*sum(L3)/D,0)→ O
: Disp O
: Pause
: Menu("DEAL OR NO DEAL?","YES",Y,"NO",N)
: Lbl N
: End
: Disp "2 BOXES LEFT"
: max(L1)→ U
: If Y=U
: Then
: min(L1)→ U
: End
: Menu("SWAP OR NO SWAP?","SWAP",S,"NO SWAP",W)
: Lbl S
: Disp "SWAPPING..."
: Y→ X
: U→ Y
: X→ U
: Lbl W
: Disp "YOUR BOX HAS:", L3(L2(Y))
: Pause
: Disp "THE OTHER:", L3(L2(U))
: Pause
: Disp "GAME OVER"
: Stop
: Lbl Y
: Disp "YOU TOOK:", O
: Disp "YOUR BOX:", L3(L2(Y))
: If O-L3(L2(Y)) ≥ 0
: Then
: Disp "GOOD DEAL"
: Else
: Disp "BAD DEAL"
: End

750 bytes


Note: the game does not detect whether you chose a box that has already previously has been chosen.

Instructions:

1. Select your box to keep. You will win this amount unless you sell it to the banker.

2. Select a set amount of boxes. The amounts revealed are what is not in your boxes. Ideally you want to eliminate as many low valued boxes as possible. Please look and scroll your list of available boxes. Box numbers that are out of play are replaced with zeroes.

3. At the end of each round, the game will give you a glance at the remaining amounts available in the name. Take the time to scroll them. Amounts no longer in play are replaced with zeroes.

4. The banker will make an offer. If believe the offer is good and you want it, take it. You can reject each deal.

5. If you reject each deal you will eventually be down to two boxes. Yours and the one remaining box not picked. The game will offer you a chance to swap boxes.
Regardless whether you deal or not, you will know the contents of your box.

Have fun!

Eddie

This blog is property of Edward Shore. © 2012



Finding the Balance Point in a Mortgage

Greetings!

Today's blog entry is about mortgages. When someone takes out a mortgage, or any loan that is to paid over time, the lender charges interest as a price for borrowing the money. Each payment that is made has two components: principal, that actually reduces the loan balance, and interest.

The beginning of the term is where the most amount of interest is paid. If the length of the loan is long enough and the interest rate is high enough, the interest eats more of the payment.

Example 1:

I take a loan for 5%, 3-year, $20,000 to finance the purchase of a computer network. Payments are to be made at the end of each month. Assume that there is no balloon amount. I would have a monthly payment of $599.41.

For the first payment I would pay $83.33 in interest ($20,000 × .05 / 12), which results in $516.08 ($599.41 - $83.33) going towards the principal. So after the first payment, the balance is $19,483.92 ($20,000.00 - $516.08). Clearly, each payment contribute to principal than interest. Happy day.

Unfortunately, mortgages are not so friendly.

Example 2:

A couple finances a purchase of a home for $264,000. They were able to secure a 30 year term at 4%. Payments are due at the end of reach month which come out to $1,260.38 a month.

For the first payment, the couple would pay $880.00 in interest, leaving only $380.38 for the principal.

Fast forward five years, the 61st payment (with balance of $238,781.43), the amount of payment contributing to interest is $795.94, leaving $464.44 for the principal.

Fast forward another five years, the 121st payment (with balance $207,989.65), the amount that contributes towards interest is $693.30, with $567.08 for the principal.

In fact it will take until the 152nd payment is made (12 years, 8 months) that more of the payment is contributed towards principal than interest. I refer to payment 152 as the balance point.

Balance Point: The Math Behind It

To find the balance point, we will take a two step approach:

1. Find the balance of the loan where the amount of interest and principal paid is equal. I call this the magic balance.
2. Use the balance to determine the payment number.

Step 1 is fairly simple.

For any payment:

I = B × R / PY
P = PMT - I = PMT - B × R / PY

Where:

I = portion of the payment that goes towards interest
P = portion of the payment that goes towards principal
PMT = payment amount
B = balance of the previous period
PY = payments per year, usually 12
R = interest rate, in decimal. (i.e. 5% = .05)

To find the required magic balance, as I will name it, equate P and I.

P = I
PMT - B × R / PY = B × R / PY
PMT = 2 × (B × R / PY)
which implies that
B = (PMT × PY) / (2 × R)

Now we can proceed to Step 2, where we can find our balance point.

Let B0 = initial loan amount, B1 = balance after 1 payment, B2 = balance after two payments, and so on.

Simply enough:
B1 = B0 - P0
B1 = B0 - (PMT - B0 × R / CY)
B1 = B0 × (1 + R / CY) - PMT

And
B2 = B1 - P1
B2 = B1 - (PMT - B1 × R / CY)
B2 = B1 × (1 + R / CY) - PMT

If we want B2 in terms of B0...

B2 = (B0 × (1 + R / CY) - PMT) × (1 + R / CY) - PMT
B2 = B0 × (1 + R / CY)^2 - P × (2 + R / CY)

Quickly we realize if we what to find B3, B4, etc...in terms of B0, the expression will grow complicated very quickly.

Thankfully, our TVM (Time Value of Money) solvers will come to our rescue! We can find the balance point simply by setting our TVM variables as such:

I/YR = R
PV = B0
PMT = PMT
FV = B from Step 1
PY = PY
Solve for N.

The balance point is ceiling(N). The ceiling function of N is N rounded up to the next integer. In essence, if N > 0, ceiling(N) = integerpart(N) + 1.

Interesting...

1. The amount of the loan has no bearing on the balance point.
2. A 5%, monthly payment loan has a balance point of 194 months (16 years, 2 months) in a 30 year term, but a balance point of 314 months (26 years, 2 months) in a 40 year term.
3. Not surprising, the balance point is bigger when the interest rate is higher. At 7%, the balance point is 241 months (20 years, 1 month) for a 30 year term, and 361 months (30 years, 1 month) for a 40 year term.
4. The terms "magic balance" and "balance point" are names I created. I am not aware of any official names used for these values (if you know, I would appreciate it).

Coming up is a program that finds the balance point. I use the TI-84+ for this program.

Note that the tvm_Pmt and tvm_N commands are from the Finance App, which is accessed by pressing APPS, 1, then 2 and 5, respectively.

TI-84+ Program PMTOFBAL

: Input "LOAN:",P
: Input "I/YR:", I
: Input "NO. PMTS:", N
: Input "P/Y:", C
: tvm_Pmt(N,I,P,0,C,C) →M
: M*C/(.02I) → X
: tvm_N(I,P,M,X,C,C) → O
: iPart(O)+1→O
: Disp "PAYMENT:", -M
: Pause
: Disp "MAGIC BALANCE:", -X
: Pause
: Disp "BALANCE POINT:",O
: Pause


Input: Loan amount, annual interest rate, number of payments (years × payments per year), payments per year

Output: Periodic payment, magic balance, and balance point. If the balance point is negative, this means for each payment, more of it will contribute towards principal than interest for the entire loan.

Thank you very much. Have a great weekend.

Eddie




This blog is property of Edward Shore. © 2012


Monday, July 23, 2012

Numerical Approximations and Debunking the Claim that π has an exact value


Greetings,

I apologize for not blogging sooner (getting over a nasty sore throat/cold). I am still working on the application series, planning to get that started on or before August 1, 2010.

Numerical Approximations

In the meantime, I am also reading about a series of numerical analysis by Namir Shammas. Please click here to go to his web page. . I am really fascinated about his paper on integration methods and polynomials he uses to better fit data.

There is also a paper on inverse distribution which can come in handy for those in statistics and probability. For example, the inverse normal distribution lets you find the z-point given the α, the level of significance. So, if the given area under the normal curve is .95, α = .05.

Is There an Exact Value for π? One Man Thinks So (He Isn't Correct)

There is this mathematician from India who claimed to have found an exact value for π, which the claimed value was well off from the true value of 3.14159265359... (off by at least .005). The way he found his value for π was by a Sieve method, which was a very confusing method involving dissecting an circle inscribed in a square, and balancing areas of circular sectors inside and outside the inscribed circle. Problem was he made an assumed value for π to conclude some convenient number. I did not get into his other two methods.

Here is the article where the errors are posted, published by Acme Science, a blog authored by Samuel Hansen (Twitter: @Samuel_Hansen): please click here.

I hope your days are well and without sickness. You can follow me on Twitter: @edward_shore. Until next time,

Eddie



Saturday, July 14, 2012

Programs for HP 48S and What's Coming Up

HP 48: Law of Sines and Cosines, Quadratic Formula, and Cubic Formula.

Hi everyone! Recently, a poster on the MoHPC HP Calculator Forum asked for programs for solving triangles and finding roots for polynomials. (link here)

I will repost the programs here. They have been done with the HP 48S.

Law of Sines:

sin(θ1)/S1 = sin(θ2)/S2. Apply this to any of the two sides and their corresponding angels.

θ which can be typed by pressing:
HP 48S: [alpha] [right shift] (F)
HP 48G: [alpha] [right shift] (F)
HP 50g: [alpha] [right shift] (T)

LAWSIN:

<< 'SIN(θ1)/S1=SIN(θ2)/S2' STEQ 30 MENU>>

Law of Cosines:

A^2=B^2+C^2-2BC cos θ

LAWCOS:

<< 'SQ(A)=SQ(B)+SQ(C)-2*B*C*COS(θ)' STEQ 30 MENU>>

30 MENU brings up the calculator's solver using whatever is stored in STEQ.

QD: (Quadratic Formula) - Credit goes to the document "1 Minute Marvels" by Wldoek Mier-Jedrzejowicz and Richard Nelson (They have this program named 'quad')

Input:

3: A
2: B
1: C

Output:

2: root 1
1: root 2

<< 3 PICK / SWAP ROT -2 * / DUP SQ ROT - √ + LASTARG - >>

SQRT: Square Root

CU: Cubic Formula Uses the program QD above. This program finds the roots of AX^3+BX^2+CX+D=0

Input:
4: A
3: B
2: C
1: D

Output:
3: root 1
2: root 2
1: root 1

Program:

<< → A B C D
<<
C 3 A * / B SQ 9 A SQ * / - 'Q' STO
C B * A SQ / 3 D * A / - 6 / B 3 ^ 27 A 3 ^ * / - 'R' STO
R Q 3 ^ R SQ + √ + 3 XROOT 'S' STO
R Q 3 ^ R SQ + √ - 3 XROOT 'T' STO
S T + B 3 A * / - 'X' STO
X
B A X * +
C B X * + A X SQ * +
QD
{Q,R,S,T,X} PURGE >> >>

What is Coming Up

Coming in August, I will do a short series which I will use a graphing calculator with programming capabilities, most likely the TI-84 Plus, to demonstrate how programming is used to assist in mathematical applications: including finding the amount of miles between two places, projectile motion, and random walks.

If you get a chance, check out the Math/Maths Podcast. Link: Pulse Project

Until then,

Eddie


This blog is property of Edward Shore. © 2012

Friday, July 6, 2012

New Book: TI nSpire 3.2 (Tech Powered Math)

For TI-nSpire: there is a new how to book written by Lucas Allen. This boom covers the latest operating system 3.2. For today and tommorrow the book is free Until July 7 through Google. After the cost is less than $10. The book is available to Kindle, and through Kindle apps.

Tech Powered Math

Friday Potluck (color calculators, orbits, baseball)

Today is going to be a hodgepodge of what's been happening over the last week. (when I am not at work, working out, sleeping, etc)

Congratulations to my cousin Gina, she gave birth to a beautiful girl, Beth on June 28! :)

The Calculator Rainbow is Back

During the last two weeks, I saw that Staples, Office Depot, and Target is getting ready for Back to School. it must be around the corner, man, we are already in July 2012! Texas Instruments has once again leashed its colorful band of TI-30x iis calcualtors in many colors: light blue, green, orange, and pink. There is also a pink version of the multi-line TI-30 XS in addition to its normal pale blue sibling. Yeah, it is hard to admit to that as a guy, I own anything pink (I called it light red at first). Even Casio gets in the act, at least at Staples, the fx-300ES PLUS has black, pink, and I think green.

I could not resist.

Orbits and Kepler's Laws

A good source to learn, brush up, and/or be entertained is the videos of bestdamntutoring. Saul Hernandez, of bestdamntutoring.com, is awesome in how he explains concepts, he speaks clearly and gets to the point.

Link to bestdamntutoring's YouTube page.

Now you know where I brushed up on Kepler's Laws, in part to hopefully prepare myself for the astronomy meeting tomorrow night (where I am meeting with my good friend Mike Grigsby):

1. Planets travel in an elliptical orbit with the sun at on of the two foci of the ellipse.

Note: The foci are located a*e units away from the center of the ellipse along the semi-major axis line. The variable a represents the length of the semi-major axis and e represents the eccentricity of the ellipse.

2. Planets sweep out at equal areas at equal times. This explains why planets move faster when they are closer to its sun and move slower when planted are away from the sun.

3. The period of an orbit can be described by the following equation:

T^2 = (4 π^2 a^3) / (G M) where

T = period of the orbit
a = length of the semi-major axis. Often, a circular orbit is used instead and hence the radius is substituted for a.
M = Mass of the central object. An assumption is made that the mass of the central object is much larger than the mass of the object being orbited.
G = Gravitational Constant. In space,
G = 6.67428 x 10^-11 m^3/(kg s) =
1.069117097 x 10^-9 ft^3/(lb s).

(Thank you TI-36X Pro. )

Baseball and WAR

In attempt to get a further understanding of Sabermetrics, the analysis of baseball and softball. We all know that part of the game of baseball includes stats galore, and at least in the United States, shaving cream pies and Gatorade baths to game day heroes. I wish there was a golly stat for pies, that would be awesome... OK I am getting off topic.

I took a look the ever vaunted stat, the WAR, or Wins Above Replacement. Basically, if a player's WAR is high, at least a 4, he is doing well. WAR is defined as a measurement of a player's "value" over a scrub (low-level minor-league) player. The goal of WAR is to assign one major value to every player that takes into account everything possible.

Thankfully, sites like www.fangraphs.com has a WAR score for just about everyone who has played baseball (at least in the US).

There are two types of WAR, one for the batters and one for the pitchers.

Generally, the batter's WAR consists of a weight batting average weighed against a dynamic league average, UBR (baser inning measure which is not a rigid formula but made of a lot of judgement calls, whose I don't know), and UZR (fielding rating calculated of the type of play and difficulty factor). None of the formula is straight forward, and as I if understand it, the weights change over time.

I didn't get much into how a pitcher's WAR is calculated, but I imagine it is complex as a batter's WAR.

First of all, where do these analysts get the time to manage the massive amount of calculations? Do they ever enjoy the game? Second, how are the weights determined? So far I have not seen anything on how the weights are calculated - are they determined by complex formulas or arbitrarily?

A Word of Thanks

Thank you to everyone who reads my comments and leave comments. I am very pleased to read that many people are enjoying this blog. This blog is one of favorite things to do. I appreciate the compliments and comments.

Enjoy the day,
Eddie


This blog is property of Edward Shore. © 2012

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...