analytics

Thursday, July 23, 2015

Solving for 3rd degree in X + 3rd degree in Y polynomials

This treats 2 dimensional polynomials that are a 3rd degree polynomial in x, without a constant term added, to a 3rd degree polynomial in y, without a constant term, and that sum equaling 1 like so:
If there's already a name for these I'm sorry I've tried searching but all the named polynomial forms seem to refer to something else...
These types of functions will cross the x axis 0,1,2, or 3 times and the y axis 0,1,2, or 3 times independently.
Suppose I wanted a function that crossed the x axis at x=-2, x=-1, and x=3 and to cross the y axis at y=-2, y=-1, and y=2... I found that these can be solved independently in a program like Maple like so:
Skip this part and come back when you've read through below: Note that every equation is solved set equal to 1, this ensures that if y is 0 or you're on the x axis, that the x terms alone will equal 1 and vice versa with x replacing y.. But the first equation above is also set equal to 1 so you get the true x or y intercepts... 
The solutions tell us what a,b,c,d,e,f need to be:

That is a cubic that goes through all those intercepts! 

Now if we want to only cross the x axis 2 times or just 1 or zero times, we can substitute imaginary numbers for the axis crossings and look at the real part of each coefficient...
In the above I've substituted i in for the -2 intercept on the y axis and then taken the real part of the coefficients for d,e,f...
It doesn't seem to matter the choice of the imaginary numbers to the final graph, just that they are each unique for each solution... It will change the coefficients to more complicated numbers though so it's good to pick simple imaginary numbers. The final graph doesn't change though...
If you've already substituted i in for one root, just pick -i as the other root and if you've already used i and -i you can use 2*i as the third for something like below that never crosses the y axis...

It's okay to reuse a complex number as both a y and an x intercept as they work independently...
Of course the choice of imaginary intercepts affects things on the imaginary plane but this is just for the real plane...

**Furthering the idea**
There's a more general case where you replace x with (x-h) and y with (y-k) that would shift the graph away from the axes... Also, I suppose this works even in higher dimensions or more variables than 2 as well...

Monday, July 20, 2015

Mapping partial sums to [0,1]

Consider the binary number .abc... between 0 and 1 and take the ith term from the sum of some series if  the ith digit of the binary number is 1, These then get summed and then every possible partial sum gets mapped to a number between 0 and 1...

Considering the binary number .101101 and the series below...
The top would equal pi/4 going to infinity and the bottom uses the 1st, 3rd, 4th, and 6th term because there are 1's in the binary number in those places...
So any number even irrational or transcendental between 0 and 1 inclusively can be used to pick out a partial sum from a series, thus mapping all those infinite partial sums to the range [0, 1]

Tuesday, July 14, 2015

Circle through two points on the Complex Plane

This formula makes a clockwise circle on the complex plane starting at point (x,y) and theta = 0,  and going through (a,b) at theta = pi, then back around to (a,b) at  theta=2*pi...





So you can use it to solve certain problems like what if you go 1/5th of the way from point (3,5) to point (-4,2) along a circular arc? The circular arc connecting the two points is:


But that is all the way with theta going to pi, one fifth of that would be pi/5 so:

One fifth of the way between those tow points along the circle is roughly at 4.38, 2.27...

**Solving for angles between unit vectors**
Another thing to do is say we have the unit vector ((2^1/2) / 2, (2^1/2) / 2), and we want to know the angle between that and ((3^1/2)/2), (1/2)) we can first make a circle with that start point and negative times each coordinate as the final point like so:

Then solve for when the formula above equals the chosen point:

It's pi/12 between those two vectors... If the angle had been the same but counterclockwise it would have read as -pi/12!

Thursday, July 9, 2015

heirarchial search

I had an idea for a website that lets you search for web pages by categories like in the picture. Each drop down box would have a list of perhaps the most popular 100 categories or subcategories and you can search deeper and deeper into the categories as far as you want and then it gives you a list of web pages that fit there in the heirarchy...


**Google to Hierarchical**

I think a way to seed the site from Google results would be to use the following to check whether one keyword could be a subcategory of another... 


R(S) is the number of results when searching for keyword S
For example:
R(sport) = 4,040,000,000
means there are that many search results on Google for the word "sport"
R(baseball) = 480,000,000
R(sport, baseball) = 476,000,000
So, R(sport, baseball) is searching for pages that match both the keywords baseball and sport, and that is almost as many as just searching for baseball by itself. So perhaps we can conclude that baseball is a subcategory of sport because R(sport) is larger... 
R(animal) = 2,200,000,000
R(anteater) = 864,000
R(animal, anteater) = 561,000
So it's not as good of a match for the subcategory relation by percentage but maybe because it's more than half as many we can keep it as a possible candidate... There might be a different keyword than animal that fits anteater better...
R(anteater, baseball) = 194,000Much less than 50% of the results for anteater alone so these probably don't have a subcategory relationship... 

So one way to start might be to look at R(x,y) where x and y are one of the top 1000 most searched for things on Google and use the information with the method above to form a category tree of the data...


Monday, July 6, 2015

Focoid's with source code

In this picture the blue dot is the centroid of all the black dots, and the red dots are what I call the focoids... The physical interpretation is that if these dots all weighed the same and were on a weightless plate, the centroid would be the place you could put one support to balance out the plate, and the focoids are two points where you could put supports so the plate would balance and there would be an even amount of weight on both supports...
I call them the focoids because of the analogy, the center of a circle is to the centroid as the focii of an ellipse are to the focoids...
In the program I wrote the dots are divided into 2 groups during the process of finding the focoids, the two groups each being a collection of points whose centroid is focoid 1 and the other whose centroid is focoid 2, so it is natural to make those points of each group a new set and find the focoids of each of those, and one could recurse until the last focoids found are the points of the original set as the centroid of just one point is the point in question... Below is shown the points from the leftmost group of the original points and it's centroid and focoids...


The program below can extend to any number and arrangement of points...


**Go Source Code**

package main

import (
    "fmt"
    "math"
)
func distance(a []float64, b []float64) float64{
    var c float64 = math.Pow(float64(a[0]-b[0]), 2) + math.Pow(float64(a[1]-b[1]), 2)
    return c
}
func centroid(a [][]float64) []float64{
    sumx :=0.0
    sumy :=0.0
    for i :=0; i<len(a); i++{
        sumx+=float64(a[i][0])
        sumy+=float64(a[i][1])
    }
    sumx /= float64(len(a))
    sumy /= float64(len(a))
    var c = []float64{
        sumx,sumy,
        }
    return c
}
func focoids(a [][]float64) ([][]float64, [][]float64, []float64, []float64){
    c := centroid(a)
    var centerred = []float64{0.0, 0.0}
    var centerblue = []float64{0.0, 0.0}
    var reds = make([][]float64, 0)
    var blues = make([][]float64,0)
    nred := 0.0
    nblue := 0.0
    for i:=0; i < len(a); i++{
        x := float64(a[i][0])
        y := float64(a[i][1])
        l := float64(len(a))
        cvx :=(c[0]-x)/distance(c, a[i])
        cvy :=(c[1]-y)/distance(c, a[i])
        c2x := (c[0]*l - x)/(l-1)-cvx
        c2y := (c[1]*l - y)/(l-1)-cvy
        c2 := []float64{c2x, c2y}
        cv := []float64{cvx, cvy}
        c2[0] /= distance(c2, cv)
        c2[1] /= distance(c2, cv)
        d := cv[0]*c2[1]-cv[1]*c2[0]
        if d < 0{
            reds = append(reds, a[i])
            centerred[0] += x
            centerred[1] += y
            nred += 1 
        }
        if d > 0{
            blues = append(blues, a[i])
            centerblue[0] += x
            centerblue[1] += y
            nblue += 1
            
        }
    }
    centerred[0]/=nred
    centerred[1]/=nred
    centerblue[0]/=nblue
    centerblue[1]/=nblue
    return reds, blues, centerred, centerblue
    
    
}
func main() {
    var a = [][]float64{
        {283,265},
        {119,99},
        {309,84},
        {461,151},
        {77,445},
        {284,451},
        {139,236},
        {678,207},
        {174,594},
        {491,525},
        {664,440},
        {531,671},
        {369,701},
    }

    var reds = make([][]float64, 0)
    var blues = make([][]float64, 0)
    var centerred = make([]float64, 2)
    var centerblue = make([]float64, 2)
    reds, blues, centerred, centerblue = focoids(a)
    fmt.Println(reds,blues)
    fmt.Println(centerred, centerblue)
    reds, blues, centerred, centerblue = focoids(blues)
    fmt.Println(reds,blues)
    fmt.Println(centerred, centerblue)
}