# What function satisfies this table?

• B
• MevsEinstein
In summary, @BvU found an approximation for the cosine function that is better than the one I found. @BvU got the variables he needed from wolfram alpha.
MevsEinstein
TL;DR Summary
I have a data set where the y values oscillate like a trig function, but not exactly.
I have a table of values (from my own analysis, not from a textbook) that represents a portion of a periodic function:
 x y 0 30 1 20 2 10 3 10 4 20 5 30
What function satisfies the table? What I know is that the function is periodic. I was thinking I could use cosine because its maximum is at x=0.

Last edited:
Hi,
You want to make a plot of your data and then think again ...

##\ ##

yucheng, hmmm27, mfb and 2 others
Your table is linear. Cos is not linear. As bvu said, think again.

phinds said:
Your table is linear
Y is oscillating up and down though.

Did you make the plot ?

And you STILL think it's a function of cos ?
MevsEinstein said:
Y is oscillating up and down though.
No, it is linearly down, then linearly up, not up down up down up down which is what oscillating describes. Some kind of ABS function, probably including a MOD 3 in there somewhere.

Correct but doesn't win the beauty prize.

One can fit a ##\cos (ax+b) + c ## through this. Or a ##\cos^2## if you want.
Do you know how to do that ?

##\ ##

Delta2, Lord Jestocost, jbriggs444 and 1 other person
MevsEinstein said:
Summary: What the title says That is not a summary !

I know that it is periodic
Then you know more than we do. Can you explain ?

##\ ##

jbriggs444
BvU said:
Correct but doesn't win the beauty prize.
View attachment 302932

One can fit a ##\cos (ax+b) + c ## through this. Or a ##\cos^2## if you want.
Do you know how to do that ?

##\ ##
I meant that cos could approximate it. The triangle wave can help, but I don't know how to shift and resize it to fit the graph.

BvU said:
Can you explain?
The plot is only a portion of the whole function. I will edit the OP.

MevsEinstein said:
The plot is only a portion of the whole function
You still know more than we do.

And you haven't answered
BvU said:
Do you know how to do that ?

##d\cos(ax+b)+c\ \ ## fits your data almost exactly when
a = 1.047186112 (##=\pi/3)##
b = 0.523625592
c = 20.00008882
d = 11.547076

Delta2 and Lord Jestocost
MevsEinstein said:
The plot is only a portion of the whole function. I will edit the OP.
That is generally a bad way to handle this. When you discover that the OP of yours was confusing and want to add more information, it is much better to add a new reply with the improved information. When you edit your OP with new information, it confuses anybody who comes into the thread and sees all the questions about confusing data... Just sayin'

yucheng, PhDeezNutz, Vanadium 50 and 1 other person
berkeman said:
That is generally a bad way to handle this. When you discover that the OP of yours was confusing and want to add more information, it is much better to add a new reply with the improved information. When you edit your OP with new information, it confuses anybody who comes into the thread and sees all the questions about confusing data... Just sayin'
Oh okay thanks for the advice.

berkeman
BvU said:
##d\cos(ax+b)+c\ \ ## fits your data almost exactly when
a = 1.047186112 (##=\pi/3)##
b = 0.523625592
c = 20.00008882
d = 11.547076

View attachment 302934
Where do you get these values from? Also, I set the amplitude as 15, The period as 5, the side shift as zero, and the y shift as 15. It makes a good approximation of the four top points but misses the bottom ones.

@BvU d is a good approximation of ##\frac{20}{\sqrt{3}}##. b is ##\frac{9763\pi}{58575}##. c is 60*Q + 800/49, where Q is the QRS constant. I got these from wolfram alpha by just entering the values and seeing which approximation is closest.

MevsEinstein said:
Where do you get these values from?
I would guess that he imagined that ##y = d\cos(ax + b) + c## would be a reasonable fitting curve. By using the points you gave it looks like he was able to solve for those four parameters.
MevsEinstein said:
Also, I set the amplitude as 15, The period as 5, the side shift as zero, and the y shift as 15. It makes a good approximation of the four top points but misses the bottom ones.
Your amplitude, 15, varies a significant amount from what @BvU calculated. And since your parameterization misses a couple points, it's not as good as the one BvU found.

SammyS
Mark44 said:
And since your parameterization misses a couple points, it's not as good as the one BvU found.
BvU asked me to find the variables before he posted his approximations.

MevsEinstein said:
BvU asked me to find the variables before he posted his approximations.
It's not relevant that you knew or didn't know the values that BvU got. The clue was that the values you found made it so that your function didn't go through or close to all of the given points.

MevsEinstein said:
Where do you get these values from?
We are trying to fit ##y = d\cos(ax + b) + c##

Those four parameters are:

Vertical scale: d
Vertical offset: c
Frequency offset: a
Phase offset: b

The way I would have obtained the values would be to start with the symmetries in the data. BVU's graph is a thing of beauty to work from for that purpose. It displays graphically the picture that should be in one's head. [My mind's eye would have tried a simpler fit to an absolute value function, but I can squint and see a cosine instead]

The horizontal midpoint is at y=20 exactly. So we can immediately take the vertical offset ##c=20##.

Now look at the values for x=1 and x=4. Those are both on the zero line of the graph of cosine. So those are one half cycle apart (could also be 1.5 cycles or 2.5, etc, but we'll not go there). From that we get that the frequency shift ##a=\frac{\pi}{3} = 1.04719755##.

The vertical midpoint is at x=2.5 exactly. You want a minimum of the cosine result there. So it would be convenient to take ##ax+b = \pi## at ##x = 2.5##. But I do not want to do things that way...

Consider that ##d## will be negative and and taken ##ax+b = 0## at ##x = 2.5##. We already have ##a = \frac{\pi}{3}## so we can solve for ##b## and get that the phase offset ##b = -\frac{5\pi}{6} = 2.6179938##

Now all we have to do is figure out the vertical scale ##d##. If you look at the data values for x=2 or x=3 compared to a center line at x=2.5, both of those are 1/3 of the way through a quarter cycle of the cosine function. So they correspond to the cosine of ##\frac{\pi}{6}##. We already have the vertical offset (##c = 20##) and want to solve for the vertical scale (##d##). We have the given data ##y=10## for both ##x## values.

So we want ##d \cos \frac{\pi}{6} + 20 = 10##. We can solve this and obtain. ##d = \frac{-10}{cos (\pi/6)} = -19.098593##

[Note that ##d## came out negative just as we wanted because we chose to center our cosine on ##x=2.5##]

If I haven't muffed some arithmetic or algebra along the way, all of this (except the decimal values, of course) should be exact.

Last edited:
SammyS, mfb and OmCheeto
This entire thread, other than the original problem statement, has been about finding a best fit. My read of the original problem is that it does not ASK for a best fit, it asks for a function. I don't get how that can be interpreted as anything other than an EXACT function, not an approximation. See my posts #3 and #7.

With exactly the data set provided, the exact function is this

f(x) = 10 * (1 + floor(abs(2.5-x)))

The OP even recognizes that this is the kind of function needed when he mentions triangular function in post#11

PhDeezNutz
phinds said:
With exactly the data set provided, the exact function is this
To be clear, that is an exact function, not the exact function.

Edit: Though William of Occam might offer some helpful advice about which function is intended.

mfb and phinds
jbriggs444 said:
To be clear, that is an exact function, not the exact function.
Good point. Still, it IS an exact function, not an approximation like all the cos stuff so the main point I was making still stands.

phinds said:
Good point. Still, it IS an exact function, not an approximation like all the cos stuff so the main point I was making still stands.
The cos stuff yields a whole family of exact matches as well. And one can always do an exact match with an interpolating polynomial.

Personally, I'd have dropped the floor function from the absolute value formula. That would yield yet another exact match.

jbriggs444 said:
The cos stuff yields a whole family of exact matches as well. And one can always do an exact match with an interpolating polynomial.
Oh. I did not realize that. I'm seeing things in this thread with long strings of digits in real numbers. I thought that those were rounded off and not exact.

jbriggs444
phinds said:
Oh. I did not realize that. I'm seeing things in this thread with long strings of digits in real numbers. I thought that those were rounded off and not exact.
The decimals are rounded, yes. Those are approximations. But I gave explicit results in terms of ##\pi## which are exact in #21. [Even if I bungled the algebra or arithmetic there, it is clear that a family of exact solutions in that form with closed form values for the four parameters exist]

phinds
But the cos function solution would not hold if the rest of the linear points were put in. Such as f(3.5) = 15 and f(4.5) = 25

I admit that my mind got immediately stuck on the triangle function and that the graph is segmented linear and, assuming that it is, cannot be represented by a cos function, so I rejected the cos function out of hand and wondered why everyone was focused on it instead of an exact solution ("exact" of course requiring the same assumption I made, which is that the function IS piece-wise linear, which seemed to be confirmed by the OP's statement about the triangle function).

jbriggs444
phinds said:
But the cos function solution would not hold if the rest of the linear points were put in. Such as f(3.5) = 15 and f(4.5) = 25

I admit that my mind got immediately stuck on the triangle function and that the graph is segmented linear and, assuming that it is, cannot be represented by a cos function, so I rejected the cos function out of hand and wondered why everyone was focused on it instead of an exact solution ("exact" of course requiring the same assumption I made, which is that the function IS piece-wise linear, which seemed to be confirmed by the OP's statement about the triangle function).
At first glance, post #8 by @BvU indeed looked wrong-headed. But then on second thought it seemed like a master stroke -- an opportunity to pursue a solution that matched what the original poster had in mind without giving away the solution that the problem's author intended. A solution that could even be exact. And all one had to do was to interpolate from the given data points in the simplest manner possible.

Tasty!

jbriggs444 said:
And all one had to do was to interpolate from the given data points in the simplest manner possible.
Hm ... I thought MY interpretation was the simplest possible

phinds said:
Hm ... I thought MY interpretation was the simplest possible
"Interpolation". Drawing a straight line between adjacent points is as simple as it gets. None of that cubic spline stuff.

jbriggs444 said:
"Interpolation". Drawing a straight line between adjacent points is as simple as it gets. None of that cubic spline stuff.
But straight line IS my interpretation.

phinds said:
But straight line IS my interpretation.
You do realize that your interpretation is a step function, not a [pair of] straight line(s), right?

jbriggs444 said:
You do realize that your interpretation is a step function, not a straight line, right?
Of course, but the data does not support a pure straight line. We seem to be talking past each other.

phinds said:
Of course, but the data does not support a pure straight line. We seem to be talking past each other.
If you graph your proposed solution, it is a set of horizontal line segments, not a pair of straight lines.

Yes, it may be the case that you come from an age where table lookups (sine tables, cosine tables, log tables, square root tables, etc) from the CRC Handbook of Chemistry and Physics are no longer the norm and the idea of linear interpolation to obtain function results not explicitly in a table is not something that you were taught in school.

When I use the word "interpolation", the idea of linear interpolation between a pair of adjacent entries in a printed table is the picture in my mind. This directly translates into drawing a series of lines between adjacent points on a graph, thereby converting a scatter plot into a line graph.

One can convert a scatter plot to a line graph in many ways. But linear interpolation between adjacent points is as simple as it gets.

Last edited:

• General Math
Replies
11
Views
1K
• General Math
Replies
5
Views
927
• General Math
Replies
15
Views
3K
• General Math
Replies
17
Views
2K
• General Math
Replies
6
Views
1K
• General Math
Replies
2
Views
967
• General Math
Replies
1
Views
887
• Set Theory, Logic, Probability, Statistics
Replies
8
Views
748
• General Math
Replies
3
Views
784
• General Math
Replies
2
Views
782