Looking for Equation for pattern

MasterOfRa

New Member
Reaction score
10
[Solved]Looking for Equation for pattern

Found A site that does it.

http://zunzun.com/

I have a set of data, That I want to find the approximate equation to generate it, as in If I plug in X, I would get something reasonably close (+-20%) to y. The data is from total values of units spawned in waves for a game, and I am trying to make a system that generates waves randomly, So I need a method to get values reasonably close to what was already there. The values are from (1 - 41 x), you had this value for (y)

I am looking for a method to determine the equation, Not the equation itself, Being that I may have this problem in the future again, And being able to do it would help.
Code:
245
699
554
2000
1302
1340
2930
6075
10280
5200
3320
4960
9200
10955
5495
35915
20945
6265
35795
86195
22435
27185
36695
30135
51195
156245
126000
56045
105695
39415
120000
126000
72000
101000
110700
210000
240000
252000
492850
492850
594300
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Well, you're looking for the Affine function or the Quadratic function depending on wether or not the values are exponential.

Affine function: f(x) = a(x-h)+k (simple canonical form)
Quadratic function: f(x) = a(h-h)²+k (simple canonical form)

I suggest you look for both of these functions (on google) and give feedback.

Once you find which function you will use, you can put another (smaller) function at the end to generate random values.

e.g.

Code:
#include <fstream>
#include <stdlib.h>
#include <time.h>

const int a = 5;
const int h = 0;
const int k = 0;

double Affine(int x)
{
	return a * (x - h) + k;
}

double Quadratic(int x)
{
	return a * ((x - h) * (x - h)) + k;
}

int MOD(double x)
{
	return rand() % int((x / 2.0) * a);
}

int main(int argc, char** argv)
{
	using namespace std;
	ofstream ofs("C:\\Output.txt");

	srand(time(NULL));
	for (int i = 1; i <= 5; i++)
	{
		ofs << "x=" << i << " Affine=" << Affine(i) << " Quadratic=" << Quadratic(i) << endl;
	}
	for (int i = 1; i <= 5; i++)
	{
		ofs << "x=" << i << " Affine=" << Affine(i) - MOD(i) << " Quadratic=" << Quadratic(i) - MOD(i) << endl;
	}
	ofs.close();
	return 0;
}
In this case, the MOD function creates a random value and multiplies it by a (5) and that value is then substracted, to the Affine/Quadratic's function result. If you play well with the values (a, h, k) and MOD you can certainly get a such result.

Output:
x=1 Affine=5 Quadratic=5
x=2 Affine=10 Quadratic=20
x=3 Affine=15 Quadratic=45
x=4 Affine=20 Quadratic=80
x=5 Affine=25 Quadratic=125
x=1 Affine=4 Quadratic=4
x=2 Affine=6 Quadratic=18
x=3 Affine=14 Quadratic=40
x=4 Affine=14 Quadratic=74
x=5 Affine=18 Quadratic=115
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I'm taking a college course (Linear Algebra) that is going over something very similar. Putting all the data into a matrix, and knowing what sort of polynomial you are looking for (like ax^3 + bx^2 + cx + d, ax^2 + bx + c, ax + b, or simply a, etc), you can solve for the 'best fit' to the data, using something called the Least Squares solution. (Keep in mind that if it looks complicated, I don't understand much of the wiki's "solution", except for this image:
42463a6f4db009c27711b37cd7b29083.png
)

If you want, I could walk through the steps. I could also test its effectiveness using a form like ax^3 + bx^2 + cx + d, which has more terms, and see if it comes up with a=0,b=0,c=-41,d=1, as we expect/hope.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top