tags:

views:

81

answers:

3

I want to add a number to a var. This number should be bigger when var is small and smaller when var is big. I have calculate the optimum values: when var=1, function should add 125. When var=50 function should add 420. I was thinking about sin function, but I have no idea how to "personalize" this function to work with it. (I am using php)

A: 

The sine function is periodic and probably not suitable for the task.

Your example is not clear: you say add 'bigger number when var is small and smaller number when var is bigger', but add 125 to 1 and 420 to 50, which contradicts the text.

One possibility is the reciprocal function - it meets your stated requirements but not your example requirements.

Given just 2 data points, we can deduce a linear relationship:

y = 125 + (420 - 125) / (50 - 1) * (x - 1)

which is approximately:

y = 119 + 6x

Check:

x =  1; y = 125
x = 50; y = 419

The approximate factor 6 is a rounding of 6.0204081632 ... which is an intriguing sequence in the fractional part.

Jonathan Leffler
The pattern is there because $\sum_{k=1}^\infty 1/50^k = \frac{1/50}{1-1/50} = 1/49$, and $1/50^k = 2^k/100^k$. Pretty cool, huh? (P.S. it takes 42 digits for it to repeat)
Jefromi
A: 

Try to make a linear equation projection.

VarAdd = Var*Slop+Start; eq [1]

125=1*Slop+Start ---1

420=50*Slop+Start –2

Solve Slop and Start then apply eq[1] any time.

Waleed A.K.
A: 

For a function with the form:

f[x_] := x + Sin[y*x + z]

Subject to the constraints

f[1] == 1 + 125 && f[50] == 50 + 420

You have

{{y -> 1/49 (-ArcSin[125] + ArcSin[420]), 
  z -> 1/49 (50 ArcSin[125] - ArcSin[420])}}

which is approximately

{{y -> 0. - 0.0247338 I, z -> 1.5708 - 5.49671 I}}

Between 0 and 70, this gives:

Graph

An approximate function, using only real values, is:

f(x) = x + 121.94629730754633 cosh(0.02473378688005212 x) + 
 121.94219707312345 sinh(0.02473378688005212 x)
Artefacto
You will need more points to optimize a sine equation:Y=A*Sin(B*X+C) +D+E*X+….;
Waleed A.K.
@Wal I'm only using two parameters and a complex valued sin.
Artefacto
@Artefacto: its not your fault but the Question is not clear
Waleed A.K.