|
I've been given some random data. X Y
0 440 6 450 12 480 18 570 24 680 30 800 36 980 42 1090 48 1520 54 1920 60 1670 66 1440 72 1380 78 1300 84 1150 90 1060 96 970 102 900 108 850 114 800 120 780 126 740 132 710 138 680 144 660
My task : To create a function which can model this data. Now my problem is, this function does not follow any one pattern. What I did instead, was break it up into 5 sections, and make a pseudo 'piece wise function.'
However,how would i go about creating one continuous function that is able to @ least closely model this data?
Here is a picture of the data : http://img118.imageshack.us/my.php?image=68941387hc2.jpg
Thanks .[/img]
   
|
Piece-wise is best for "sharp" graphs like this one, but I think for this situation an exponential or polynomial function is your best bet. Use your TI-81 calculator to create a ExpReg for data in L1 and L2 (you have to put the data in those).
|
On December 12 2007 13:01 fanatacist wrote: Piece-wise is best for "sharp" graphs like this one, but I think for this situation an exponential or polynomial function is your best bet. Use your TI-81 calculator to create a ExpReg for data in L1 and L2 (you have to put the data in those).
yeah, pretty much what he said, why would you come to teamliquid for math homework
TL IT UP PEOPLE TL IT UP SO HE NEVER ASKS AGAIN
|
Melbourne5338 Posts
|
Rofl Zealot icons own your math!
(This shit just got zeal rushed)
|
It looks kind of like a Laplacian
c * e^(a |x - b| )
|
Kennigit
Canada19447 Posts
i think i have found the problem affecting your math homework.
|
Plot the points in a graphing calculator and you will receive your function
|
On December 12 2007 14:01 LegendaryDreams wrote: Plot the points in a graphing calculator and you will receive your function
GENIUS!
It's not really a Laplacian since it lacks symmetry... I'd go with the cubic spline.
|
You could make a 25th order polynomial (or would it be 24th?) that looks something like: y = a*x^24 + b*x^23...... + c*x+d
Plug in your data sets and you'll get osmething like a 25 by 25 matrix with a, b, c...... as your variables. Ummm, it might be a pain in the ass to invert that manually, so use some sort of program like maple or mathematica to invert it for you
|
Bill307
Canada9103 Posts
In general, you are looking for some method of Interpolation.
In this case, a cubic spline would be a much better choice than a 25th order polynomial. Firstly, a spline takes much less time to compute. Second, such a high-order polynomial will suffer from Runge's phenomenon, which basically means your resulting function will look absolutely horrendous towards the ends of your data.
|
United States24615 Posts
You could use the solver in excel to minimize chi squared when fitting this to any function, and technically you would be accomplishing the goal you described. Is there any limit on how imprecise this can be? Otherwise a high order polynomial would be easy (3 minutes in excel, but no topic specific software help needed). If you decide to do it my way but don't know how, pm me. BTW, my method works for any type of function, not just polynomials (just minimize the sum of the difference of the square of the variations of the theoretical data points with the experimental data points, by toggling the parameters of the theoretical equation).
Edit: er I mean, minimize the sum of the square of the differences :-p
|
|
I'm a bit confused between Spline interpolation and regular piece wise function.
To be more exact, what I did is :
f'x [0,54] + g'x [54,72] + h'x [ 72,104] + j'x [104,144] where the [a,b] is the x intervals.
I took the data given. I saw that from 0-54 it seemed like a quartic regression. So I do the regression and get a correlation of .993. I then imput this as f'x on the interval of [0-54]. Repeating the process with g'x, h'x etc.
What is the difference between this and a piecewise function?
|
Bill307
Canada9103 Posts
(The following is a response to one of kdog's PMs. I'm posting it here so that others can see it as well. In summary, I explain how to create a (natural) cubic spline and do a short 3-point example.)
Hi kdog,
I haven't done cubic splines in about 9 months, but I'll try my best to recall everything. Ignoring what Wikipedia says (because I don't understand it much myself ), the general idea is as follows: you want to have a cubic function between every two data points, and when two functions meet at a data point, their 1st AND 2nd derivatives are equal. (Earlier I forgot that the 2nd derivatives also have to be equal.)
Let's use your example: x_0 = 0, y_0 = 5 x_1 = 1, y_1 = 6 x_2 = 2, y_2 = 10 x_3 = 3, y_3 = 20 x_4 = 4, y_4 = 8 x_5 = 5, y_5 = 7
So we will define 5 functions as follows:
f_i(x) = (A_i) + (B_i * x) + (C_i * x^2) + (D_i * x^3)
for i = 0, 1, 2, 3, 4
(I put each term in parentheses for better readability.)
Each function f_i is defined between points x_i and x_i+1.
Since each function has 4 unknown constants, and there are 5 functions, that means we have 20 unknown constants in total to determine. Therefore, we need 20 equations that constrain them.
First of all, because we want the combined function to pass through each data point, we have to satisfy the following equations:
f_i(x_i) = y_i (i.e. f_i has the correct value at its first endpoint) f_i(x_i+1) = y_i+1 (i.e. f_i has the correct value at its second endpoint)
for i = 0, 1, 2, 3, 4
examples: f_0(0) = 5 f_0(1) = 6 f_1(1) = 6 f_1(2) = 10 f_2(2) = 10 f_2(3) = 20 etc.
This gives us 10 equations. Second, we want the 1st and 2nd derivatives of the combined function to be continuous as well, i.e. we want the combined function to be smooth. We know that in each piece, the derivatives of a cubic function are continuous. So we just need to make sure the derivatives match-up at each data point, where two of the functions (say, f_i and f_i+1) intersect. That is, we must also satisfy the following equations:
f_i'(x_i+1) = f_i+1'(x_i+1) f_i''(x_i+1) = f_i+1''(x_i+1)
for i = 0, 1, 2, 3
examples: f_0'(1) = f_1'(1) f_0''(1) = f_1''(1) f_1'(2) = f_2'(2) f_1''(2) = f_2''(2) f_2'(3) = f_3'(3) f_2''(3) = f_3''(3) etc.
This gives us an additional 2*4 = 8 equations, for a total of 18. To create the last two equations, we apply extra boundary conditions at the first and last data points. There are a variety of options here, but a common one is called the "natural cubic spline", where the 2nd derivatives at the first and last data points are 0, i.e.:
f_0''(0) = 0 f_4''(5) = 0
This gives us a system of 20 equations and 20 unknown constants, allowing us to solve for the 20 unknown constants. If you were to do this by hand, you'd have to row-reduce a 20x20 matrix, so naturally I'm afraid I won't do that for your example . Realistically, you'd want to use a program that can do it automatically for you. For the data you gave us in your blog post, if you have 25 data points then you'd end up with (25-1)*4 = 96 equations and 96 unknown constants: easy for a computer, but death for a human .
I can quickly do a natural cubic spline between 3 data points, though, e.g.:
x_0 = 0, y_0 = 5 x_1 = 1, y_1 = 6 x_2 = 2, y_2 = 10
f_0 = A + Bx + Cx^2 + Dx^3 f_1 = E + Fx + Gx^2 + Hx^3
We end up with 8 equations:
f_0(0) = 5 : A = 5 f_0(1) = 6 : A + B + C + D = 6 f_1(1) = 6 : E + F + G + H = 6 f_1(2) = 10 : E + 2F + 4G + 8H = 10
f_0'(1) = f_1'(1) : B + 2C + 3D = F + 2G + 3H or B + 2C + 3D - F - 2G - 3H = 0 f_0''(1) = f_1''(1) : 2C + 6D = 2G + 6H or 2C + 6D - 2G - 6H = 0
(boundary conditions for a natural cubic spline f_0''(0) = 0 : 2C = 0 f_1''(2) = 0 : 2G + 12H = 0
We can now create an 8x8 matrix to solve. You could solve it by hand by row-reducing the matrix, but I chose to use Mathematica instead .
So the end result is the following function:
f(x) = { 5 + (1/4 * x) + (3/4 * x^3), for x between 0 and 1 { 13/2 - (17/4 * x) + (9/2 * x^2) - (3/4 * x^3), for x between 1 and 2
Graph plotted using MathGV:
|
Hi again.
In Mathematica, when creating a Matrix; is it possible to define each piece of it?
[/QUOTE]
In your example you used variables of (A, B, C, D) for fx 1. (E, F,G ,H) for fx2. In a 96 x 96, I will run out of letters, so (a, b , c ,d) fx1, (a1, b1, c1, d1) fx2 and so forth until fx95.
Can I also , once I have defined each piece of it, import a data set into it?
Referring back to pic, can i do something like make a list to import into the matrix?
a1 = 2 a2 = 3 b1 = 3 b2= 4 Etc With "else = 0" for a3, a4 .... a95
Importing all the data directly to the matrix would make the process much easier.
Thanks
|
|
|
|