Find the number pattern

42 Views Asked by At

Goal: find 1 equation to generate -4,2,10,6,3 on looping

  • Output -4 on 1st iteration
  • Output 2 on 2nd iteration
  • Output 10on 3rd iteration
  • Output 6 on 4th iteration
  • Output 3 on 5th iteration

In each iteration you can do whatever you want, except explicitly output the number.

2

There are 2 best solutions below

0
On

You can fit a fifth-degree polynomial to get an answer; for this there are standard techniques you can look up. Unfortunately, it's probably "overfitting" and won't be terribly useful for modeling any real-world situation.

0
On

So do you mean that you want to find a function $f$ such that

$$f(-4) = 2 \qquad f(-2) = 10 \qquad f(10) = 6 \qquad f(6) = 3 \qquad f(3) = -4$$

?

If so, then you can simply use Lagrange interpolation to give

$$f(x) = -2p_{-4}(x)+10p_{-2}(x)+6p_{10}(x)+3p_{6}(x)-4p_{3}(x)$$

where

$$p_{-4}(x) = \frac{(x+2)(x-10)(x-6)(x-3)}{(-4+2)(-4-10)(-4-6)(-4-3)}$$

$$p_{-2}(x) = \frac{(x+4)(x-10)(x-6)(x-3)}{(-2+4)(-2-10)(-2-6)(-2-3)}$$

$$p_{10}(x) = \frac{(x+4)(x+2)(x-6)(x-3)}{(10+4)(10+2)(10-6)(10-3)}$$

$$p_{6}(x) = \frac{(x+4)(x+2)(x-10)(x-3)}{(6+4)(6+2)(6-10)(6-3)}$$

$$p_{3}(x) = \frac{(x+4)(x+2)(x-10)(x-6)}{(3+4)(3+2)(3-10)(3-6)}$$