Omnimaga

General Discussion => Other Discussions => Math and Science => Topic started by: Xeda112358 on March 31, 2011, 12:14:48 am

Title: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on March 31, 2011, 12:14:48 am
So pretty much, this is a direct copy/paste from my post on UTI:
Okee dokey then, so I have been working for the past two days on forming equations for finite sets of data. For example, if I have {0,-33,i,27,6}, I would want to find an equation where if x=0, then the result is 0, and if x=1, the result is -33, et cetera. I have a method that accomplishes this and I have explored it much in the past few days, but I get the feeling there is either an easier way or this method is just something I haven't gotten to, yet. Anyway, here is what I do...
First, to make things simpler, I want to make two sets (one real and the other imaginary), so I end up with:
{0,-33,0,27,6}+i{0,0,1,0,0}. I want to tackle one at a time, so I arrange the first list into a column like so:
Code: [Select]
  0
-33
  0
 27
  6
Now from there, you make a second column that is the difference of Un+1 and Un:
Code: [Select]
  0
-33   -33-0=-33
  0   0--33=33
 27    27-0=27
  6    6-27=-21
And from then you add another column using the same idea until you reach one element in the column:
(http://www.unitedti.org/forum/uploads/post-28158-0-51616500-1301543933.gif)
Now from there, fill the last column space with 30. From there, you can work your way backwards to fill in the rest of the columns:
(http://www.unitedti.org/forum/uploads/post-28158-0-95868300-1301540032.gif)
At this point, we should denote the column spaces in this manner:
a-First column space (the original numbers)
b-Second column space
c-Third column space
d-Fourth column space
e-Last column space

So, looking at the matrix, e follows the equation y=30. Now we move to d which must be -162+sum(e,n,0,x) or -162+30x. c is going to be 300+sum(d,x,0,n) which can be represented as 300-162x+30(x2+x)/2). This can be simplified, but for the sake of making the concept clear, I will not simplify it. As we continue with the last two, we get:
b=-201+300x-162(x2+x)/2+30(x3+3x2+2x)/6
a=-201x+300(x2+x)/2-162(x3+3x2+2x)/6+30(x4+6x3+11x2+6x)/24

And that is the equation for the real part of the original set of numbers. Applying the same method, we get for the imaginary part:
ai=i(-10x+25(x2+x)/2-21(x3+3x2+2x)/6+6(x4+6x3+11x2+6x)/24)

And now we simply need to combine the two equations to get the ridiculously large equation:
-201x+300(x2+x)/2-162(x3+3x2+2x)/6+30(x4+6x3+11x2+6x)/24+i(-10x+25(x2+x)/2-21(x3+3x2+2x)/6+6(x4+6x3+11x2+6x)/24)

Anyway, that is the method I have used and explored and that is the long, tedious way of obtaining results. The faster way will require the use or knowledge of Pascal's Triangle and by knowledge... hehehe, this ties into some of my other explorations that I haven't gotten into here...
For a quick way to obtain the diagonals, let us represent those as {a,z,y,x,w,...} and we can look at it in this form:
Code: [Select]
[[a l m n o ...
  b z
  c   y
  d     x
  e       w
...         ]]
a=a
z=b-a
y=c-2b+a
x=d-3c+3b-a
w=e-4d+6c-3b+a
...
If you notice those coefficients, you will note the relationship to Pascal's Triangle. There is another relationship you may not have noticed in the first example. Firstly, it should be pretty clear that taking the values in row 1, we have the coefficients required for the end equation. Those coefficients go along with some polynomial and those polynomials are the equations to the diagonals of Pascal's Triangle. So, if the first diagonal (all 1s) is represented as P0, then the equations are as follows:
P0=1
P1=x
P2=(x2+x)/2
P3=(x3+3x2+2x)/6
P4=(x4+6x3+11x2+6x)/24
...
The pattern is fairly easy:
P0=1
P1=Σ1
P2=ΣΣ1
P3=ΣΣΣ1
P4=ΣΣΣΣ1
So P4 should be read as the sum of the sum of the sum of the sum of 1. SO using the above notation (in the code box), the equation that hits {a,b,c,d,e,...} would be a*P0+l*P1+m*P2+n*P3+o*P4...

So it would be nice to have {a,l,m,n,o,...}, right? Well that, too, makes use of Px as well as an alternating negative sign. As examples:
a=a
l=z-y+x-w...
m=y-2x+3w-4v...
n=x-3w+6v-10u...
o=w-4v+10u...
...
If you notice the coefficients there, you will note that:
a= uses 0 for its coefficients
l= uses P0 for its coefficients
m= uses P1 for its coefficients
n= uses P2 for its coefficients
o= uses P3 for its coefficients
...

So now with that in mind, we can model this simple set of data: {π²,-3,6,2}
a=π²
b=-3
c=6
d=2

So:
Code: [Select]
a=a         = π²        = π²
z=b-a       = -3-π²     = -3-π²
y=c-2b+a    = 6+6+π²    = 12+π²
x=d-3c+3b-a = 2-18-9-π² = -25-π²

Code: [Select]
a=a         = π²                  = π²
l=z-y+x     = -3-π²-12-π²-25-π²   = -40-3π²
m=y-2x      = 12+π²+50+2π²         = 62+3π²
n=x         = -25-π²              = -25-π²
And finally the equation:
π²P0+(-40-3π²)P1+(62+3π²)P2+(-25-π²)P3
Which turns to:
π²+(-40-3π²)x+(62+3π²)(x2+x)/2+(-25-π²)(x3+3x2+2x)/6

So anywho, there are probably a few things I missed and maybe a few mistakes, but is there an easier approach to this?
Title: Re: Sums, Pascal, and Equations for Sets
Post by: AngelFish on March 31, 2011, 02:01:35 am
I hope I'm not the only person whose eyes glazed over and skipped straight to the last line :P

Now to read the thing for real to figure out what you were doing that could be done more efficiently.

EDIT: What you're talking about is known as Interpolation. It's actually a very well developed field, but I've never seen an approach quite like yours. In any case, for any set of N points, there is at least one function of degree N-1 that fits all of those points exactly.  So, I'd recommend looking at Gaussian Interpolation. Just be warned that problems can arise with Interpolation because the functions may not behave realistically in the intervening interval.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: phenomist on March 31, 2011, 02:04:29 am
I believe this is Newton interpolation. Note that the non-coefficients can be reexpressed as x/0!, x(x+1)/1!, x(x+1)(x+2)/2!, etc. Unless you already noticed that :P
Title: Re: Sums, Pascal, and Equations for Sets
Post by: AngelFish on March 31, 2011, 02:06:41 am
Darn it, ninja'd by a post after my own :P

Also, that should be Polynomial interpolation in my previous post, not Gaussian.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on March 31, 2011, 10:19:49 am
Ah, cool! And how exactly might I go about finding these coefficients besides using the Riemann Zeta function+Horowitz Zeta function? Right now, I am simply using my knowledge of the equations, so I only have up to 47 degree polynomials readily available. I was pretty curious about what I was doing after a friend challenged me to model {0,1,0,1,0,1}... We compared it to sine and since he didn't know about Taylor's series, I showed him that. Although, though the two equations matched certain parts of the sine curve, the Taylor series matched a slightly different part and is used for estimating sine. The one I used was only meant to hit the points that sine happened to hit XD Anywho, I will check out this Interpolation stuff...

But yeah, the main thing I want to attack is finding those polynomials! :D There are some very obvious patterns like with those summation equations I was working on and it uses those (or at least I used those to find the Pascal's diagonals).

Not an EDIT: Wait, do those coefficients follow like x(x+1)(x+2)(x+3)...(x+n)/n! ? Because I used the whole sum of the sum of the (et cetera) idea and I was simply using some notes on other ventures I made...
The image:
http://www.omnimaga.org/index.php?action=dlattach;topic=5618.0;attach=4841;image
The topic:
http://ourl.ca/8215/150613

The last one includes a bunch of my notes, too :)

EDIT:
Also:
In any case, for any set of N points, there is at least one function of degree N-1 that fits all of those points exactly.
Actually, so long as the set is finite, there are infinitely many equations that pass through those points. That was another thing I was trying to show with this. All you need to do is add any number to the end of the set and you change the equation. It will still pass through the set of numbers that you want :) And then you can add some other arbitrary number and so on :)
Title: Re: Sums, Pascal, and Equations for Sets
Post by: AngelFish on March 31, 2011, 01:30:24 pm
Quote
Actually, so long as the set is finite, there are infinitely many equations that pass through those points. That was another thing I was trying to show with this. All you need to do is add any number to the end of the set and you change the equation. It will still pass through the set of numbers that you want Smiley And then you can add some other arbitrary number and so on

True, but the existence of at least one distinct solution is a sufficient condition ;)

Also, the set {0,1,0,1,0,1,0,1,...} could probably be described by Sine or Cosine, but I think the function (2)^(x mod 2)-1 is much simpler.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on March 31, 2011, 02:26:38 pm
Oh, yeah, I know, but my friend wanted to see how the equation handled a 5th degree polynomial approximation of a sin equation :D Again, he had never heard of Taylor series, so he was fairly excited when he saw me working with these. I guess he thought it would be a challenge xD. Anywho, here is a comparison...

EDIT: Cool! I just checked and the diagonals in Pascal's Triangle do seem to follow the pattern where:
Pn=x(x+1)(x+2)...(x+n-1)/n!

Cool! That will be mightily useful!
Title: Re: Sums, Pascal, and Equations for Sets
Post by: phenomist on March 31, 2011, 06:28:09 pm

Also, the set {0,1,0,1,0,1,0,1,...} could probably be described by Sine or Cosine, but I think the function (2)^(x mod 2)-1 is much simpler.


How about the function (x mod 2)? :P


@Xeda: might help: http://en.wikipedia.org/wiki/Newton_polynomial. If you independently worked all of that out, that's pretty impressive :P
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on March 31, 2011, 10:09:17 pm
Disclaimer: I have had coffee for the first time this year and coffee=drugs for Zedas :w00t:. Read the following at your own risk because I am completely buzzed on coffee and I cannot keep my thoughts in order... I'ma go do some maths for now  :crazy:
Not an Edit: Cool, I can use emoticons!

Hehe, I cannot seem to get things like Linear Algebra (!_!) or things like that, but all of the stuff I work on I do independently. :/ The problem with that is that before this semester of college, I was never exposed to formal stuff (or at least rarely exposed), so my notation tends to be a little on the questionable side :D The other problem is that whenever I go to Wolfram to see if my ideas already exist, I cannot find answers because I cannot read any of it and I don't know what to look for. For example, back in ninth grade I got super excited because I was playing around on my calc with this really cool sine function thingamabob and I started noticing a pattern. By the end of the night I found a way to do things like finding the exact value of sin(171pi/1024)! That November, I was going to a math competition and I showed off my cool formula to a professor and they didn't recognise it, but they said "Here's my e-mail and check Wolfram.com for" and he used a term I forgot, but it described taking the square root of the square root of the... you get the idea. Eventually I found out it was just some random and obscure pattern. Since then I found another method, but I cannot find it on wolfram x.x Another example is last year (26 January 2010) I cracked open an old trig book that a friend gave me in seventh grade when a little slip of paper fell out that said N=.5A2+.5A and I had a drawing of bricks next to it and I remembered, "Oh, that was the day my mother had to take me to the bank with her and I decided to count bricks..." I then got distracted and I counted at the top in the center 1 brick. Then there were two bricks below that touched that brick. Then three and four and five, et cetera. I spent that day finding a way to make an equation for it (I felt special because I taught myself Algebra using an old TI-99 in fourth grade... there is a nice story, there, too). Back on topic... I eventually worked out that if I took the number of bricks there were (heightwise) and divided it by two, I could add .5 and multiply by the number of bricks tall it was to get all of the bricks! Anywho, I found that slip of paper and I was waiting to take my French midterm so I thought "Huh, what if I had a pyramid that had one brick on top, 4 below that and 9 below that, and so on..." So I got to working on that and I found the equation for that. It that hit me after the exam that I was finding an equation for the sum of X2! Then I tried doing that with X3 and I found that and then I got home and for the rest of that week I worked my way up to X6. So blah, blah, blah, I worked at it for a long time and then put it aside for the month of March. The work to find X7 Had been so much that I decided to instead work at finding a pattern before attempting anything more. Then, suddenly, I found a pattern in the first week of April! So that night I worked my way up to X9 and over the next three days up to X15. The problem was, the pattern was still difficult for me to grasp and so I took another month to find an algorithm to find the coefficients I needed and within 15 minutes, I was able to expand my collection of equations from the sum of X15 up to X47! When I finally got internet, I posted this (http://www.unitedti.org/forum/index.php?showtopic=9474) over on UTI using an example my poor TI-89 could handle.

So yeah, I actually am not all that good at math, but math is one of those few things that I can get absolutely consumed in and I am bound to eventually come across things. That was how I noticed that the diagonals in Pascal's triangle were simply the sums of the previous diagonal. Of course, I used the algorithm I came up with before to find those sums, so I didn't see that they followed X(X+1)(X+2)...(X+n-1)/n!, so that will be interesting to explore! There is so much that I randomly encounter and I don't even have a brain for math !_! I just have the devotion and it is the only thing I have the devotion for  :'(

EDIT: Sorry for any glaring grammatical errors... read the note at the top for my excuse...
Title: Re: Sums, Pascal, and Equations for Sets
Post by: AngelFish on March 31, 2011, 11:29:01 pm
I read this in a mentally hyper/high pitched voice it was was kind of hilarious  ;D

I think most people in America would disagree with you about not being good at math though...
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on March 31, 2011, 11:33:00 pm
I don't know, I have a tough time grasping concepts in math, but I work at it so much that I eventually run across things :/
Title: Re: Sums, Pascal, and Equations for Sets
Post by: phenomist on April 02, 2011, 03:25:01 am
Well, you don't need to formalize stuff just like in "everybody else's way". (Just take Ramanujan, for instance.) You can do some pretty amazing stuff independently that nobody else has considered.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on April 07, 2011, 08:44:58 pm
Okay, so I was playing around with that idea yesterday about how the diagonals in Pascal's triangle are simply the sum of the diagonal before it and I combined that with some other things I did with it and I came up with a few things:
First, Pn(r)=(r+n)!/(r!n!). This means that if you want to check the third diagonal for the seventh number, n=2 and r=6 (because they offset at 0). This yields:
P2(6)=(6+2)!/(6!2!)
P2(6)=40320/1440
P2(6)=28

Because of the closure property under addition and multiplication of integers, we also have that Pn(r)=Pr(n) which can be useful, too. We can also look at nCr alternatively as:
Pn(r)=r+nCr
or
Pn(r)=r+nCn

We also have the definition of nCr as r+nCn=n!/(r!(n-r)!), so we can show the above statements true:

r+nCr=(r+n)!/r!((r+n)-r)!
r+nCr=(r+n)!/r!n!
and:
r+nCn=(r+n)!/n!((r+n)-n)!
r+nCn=(r+n)!/n!r!

So yeah, just a little fun XD I am definitely adding this to my master notebook :D
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on April 11, 2011, 02:35:09 am
Okay, so I have a program made to automate the process of finding an equation for a set of points. You input a list of points and it stores the equation into Y1 :) The only problem which I have to fix is the calculators rounding error :/ since it has to divide by factorials... blegh Anywho, I'll fix it up tomorrow :)
Title: Re: Sums, Pascal, and Equations for Sets
Post by: jnesselr on April 11, 2011, 07:28:36 am
That's kinda epic Zeda.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on April 11, 2011, 08:10:39 am
^_^ I made one that doesn't have all those decimals, but it is slower to graph. Still, it makes it more accurate when fitting 15 degree polynomials  XD
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on September 05, 2011, 09:26:27 pm
So here is an update. I made a program in Python that will do the same thing as Interpl8 for the calc (pretty much). Just input the list (don't add an ending bracket or starting one) and then when it asks for the file to output to, just do something like equation.txt
Title: Re: Sums, Pascal, and Equations for Sets
Post by: 3rik on September 06, 2011, 11:56:11 am
I'm not sure if I understood this topic.
Are you trying to find some thing like y=(1.25+0.25i)x4+(-19.5-2i)x3+(82.75+4.75i)x2+(-97.5-3i)x+0 for the set {0, -33, i, 27, 6}?
I used matrices to find the answer and it didn't seem as complicated as that.

I am not in college math so if I totally missed the point please disregard this post.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on September 06, 2011, 04:50:51 pm
This is just my own playing around with math and I don't doubt that there is a much easier way to do this. The method I used is derived from a matrix, actually, too. However, taking the time to squish that matrix down from two dimensions to one was the long, drawn out part. I came up with this as kind of an offshoot of some bigger math problems that I was working on, but I thought it was a neat idea. So yeah, pretty much, this method takes a finite set of data and finds an equation that can model that data.
Title: Re: Sums, Pascal, and Equations for Sets
Post by: 3rik on September 06, 2011, 11:24:30 pm
Okay. I do stuff like that too. If you want to see my precalculus method of doing it I put it here.

Spoiler For my method of solving the problem if you're curious:

So the objective of this problem is to find a (n-1)th degree polynomial for a finite set of data with n terms.

So if the set has five terms then the general equation would be

ax4+bx3+cx2+dx+e=t

where x is the term number minus 1 and t is the term and a, b, c, d, e are the coefficients.

Using the example of {0, -33 , i, 27, 6}, we can substitute the values in for x and t.

(in this case we have to make the assumption that 0^0 = 1 or else everything falls apart)

0a + 0b + 0c + 0d + 1e = 0
1a + 1b + 1c + 1d + 1e = -33
16a + 8b + 4c + 2d + 1e = i
81a + 27b + 9c + 3d + 1e = 27
256a + 64b + 16c + 4d + 1e = 6

This is can be solved more easily by using matrices (really you can kinda skip to this step)

[A] =
00001
11111
168421
8127931
256641641

[B] =
a
b
c
d
e

[C] =
0
-33
i
27
6

(excuse my messy matrices)

So [A]*[B] = [C]

Since we already know what [A] and [C] are, we need to solve for [B]

[A]-1*[A]*[B]=[A]-1*[C]
[B]=[A]-1*[C]

Multiply and you'll have your coefficients!

(http://i51.tinypic.com/2vtp3e0.jpg)

I know the TI-84 and the TI-Nspire CX can handle inverse matrices and I know the Nspire can handle non-real values in the matrices.

Otherwise writing algorithms for this isn't that hard to do.

It works for any length of set as long as you can calculate (n-1)(n-1); but the calculator is often imprecise with inverse matrices.

Title: Re: Sums, Pascal, and Equations for Sets
Post by: Xeda112358 on August 05, 2012, 05:02:48 pm
necro update >.>

Here is an interpolation program that allows you to supply your own x list and y list. Unfortunately, this requires BatLib to be installed as it uses the number to string function (it makes the program much faster, smaller, and I don't need to use other variables).

Now for some more stuff..

I have been working on some pretty cool math that has lead me to figuring out how to make different interpolation models. For example, I could before model data with a polynomial equation, but now I have an algorithm to do exponential data. Here is an example:

I want:
     f(0)=a
     f(1)=b
     f(2)=c
The formula is scary, but really cool:
     f(x)=cx(x-1)/2bx(2-x)a(x-2)(x-1)/2
Try it, it works :D It was a simple process, too. All I did was say:
     eu(0)=a
     eu(1)=b
     eu(2)=c
Then:
     u(0)=ln(a)
     u(1)=ln(b)
     u(2)=ln(c)
Using the first algorithm that I established:
     ln(a) |                    |
     ln(b) |ln(b)-ln(a)         |
     ln(c) |ln(c)-ln(b)         |ln(c)-2ln(b)+ln(a)
;=======
     ln(a) |3ln(b)-2ln(a)-ln(c) |ln(c)-2ln(b)+ln(a)
     ln(b) |ln(b)-ln(a)         |ln(c)-2ln(b)+ln(a)
     ln(c) |ln(c)-ln(b)         |ln(c)-2ln(b)+ln(a)

Then u(x)=ln(a)+x(3ln(b)-2ln(a)-ln(c))+x(x+1)/2(ln(c)-2ln(b)+ln(a)).
Now we use some logarithm rules to simplify:
     u(x)=ln(a)+ln(b3x)-ln(a2x)-ln(cx)+ln(cx(x+1)/2)-ln(bx(x+1))+ln(ax(x+1)/2).
Now substitute in the u(x):
     f(x)=eln(a)+ln(b3x)-ln(a2x)-ln(cx)+ln(cx(x+1)/2)-ln(bx(x+1))+ln(ax(x+1)/2)
Now we reorganise this to make it easier to apply more rules:
     f(x)=eln(a)+ln(b3x)+ln(cx(x+1)/2)+ln(ax(x+1)/2)-ln(a2x)-ln(cx)-ln(bx(x+1))
     f(x)=eln(a)+ln(b3x)+ln(cx(x+1)/2)+ln(ax(x+1)/2)-(ln(a2x)+ln(cx)+ln(bx(x+1)))
     f(x)=eln(a)+ln(b3x)+ln(cx(x+1)/2)+ln(ax(x+1)/2)/e(ln(a2x)+ln(cx)+ln(bx(x+1)))
Now we use more simplification with logs and exponents of the same base:
     f(x)=(ab3xcx(x+1)/2ax(x+1)/2/(a2xcxbx(x+1))
     f(x)=(b3xcx(x+1)/2ax(x+1)/2+1/(a2xcxbx(x+1))
     f(x)=(b3x-x(x+1)cx(x+1)/2-xax(x+1)/2+1-2x
     f(x)=(b-x(x-2)cx(x-1)/2a(x-1)(x-2)/2
     f(x)=(bx(2-x)cx(x-1)/2a(x-1)(x-2)/2


I also went through a similar process for using sine and cosine, but it had some sign issues :/ (because of how arcsine and arccosine are defined to work as a function). It actually worked for the values I used, but I am pretty sure I put together a data set that failed.

In any event, it might be useful to make a small interpolation suite. It would probably be nice to have a version in BASIC so that folks can study it, but another version in assembly to make a faster and more efficient process.