How to easily create a polynomial function that gives a desired output?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I am looking for an easy way (formula or algorithm) to create a polynomial function that gives the arbitrary preset output for the first values of x. For instance, the desired output can be $y = 1, 2, 3, 4, 5, 6, 100$ for $x = 1, 2, 3, 4, 5, 6, 7$. I can create one of the many functions by hand as:
$y = x + (x-1)(x-2)(x-3)(x-4)(x-5)(x-6)cdot frac93720.$
But for other desired outputs it is really painstaking. For example, I am working now with the desired output $y = 2, 10, 12, 16, 17, 18, 19, 200, 300$ when $x = 1, 2, 3, 4, 5, 6, 7, 8, 9$.
Notes:
$x$ is always a natural positive number ($x > 0$). It doesn't matter what happens for other values of $x$ (greater than the ones given).
- I am looking for a easy way, as I don't know / I don't have / I have no experience with math related software.
- Also for a polynomial (or similar simple) function, as my mathematical background is quite limited, so I don't know any gamma, delta or other functions, series, etc.
- This quest is simply for recreation, to show friends how there are different solutions to the problems of the type: "Find the next term in this succession"
polynomials
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
3
down vote
favorite
I am looking for an easy way (formula or algorithm) to create a polynomial function that gives the arbitrary preset output for the first values of x. For instance, the desired output can be $y = 1, 2, 3, 4, 5, 6, 100$ for $x = 1, 2, 3, 4, 5, 6, 7$. I can create one of the many functions by hand as:
$y = x + (x-1)(x-2)(x-3)(x-4)(x-5)(x-6)cdot frac93720.$
But for other desired outputs it is really painstaking. For example, I am working now with the desired output $y = 2, 10, 12, 16, 17, 18, 19, 200, 300$ when $x = 1, 2, 3, 4, 5, 6, 7, 8, 9$.
Notes:
$x$ is always a natural positive number ($x > 0$). It doesn't matter what happens for other values of $x$ (greater than the ones given).
- I am looking for a easy way, as I don't know / I don't have / I have no experience with math related software.
- Also for a polynomial (or similar simple) function, as my mathematical background is quite limited, so I don't know any gamma, delta or other functions, series, etc.
- This quest is simply for recreation, to show friends how there are different solutions to the problems of the type: "Find the next term in this succession"
polynomials
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
Look-up "Lagrange interpolation"
– Gabriel Romon
1 hour ago
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am looking for an easy way (formula or algorithm) to create a polynomial function that gives the arbitrary preset output for the first values of x. For instance, the desired output can be $y = 1, 2, 3, 4, 5, 6, 100$ for $x = 1, 2, 3, 4, 5, 6, 7$. I can create one of the many functions by hand as:
$y = x + (x-1)(x-2)(x-3)(x-4)(x-5)(x-6)cdot frac93720.$
But for other desired outputs it is really painstaking. For example, I am working now with the desired output $y = 2, 10, 12, 16, 17, 18, 19, 200, 300$ when $x = 1, 2, 3, 4, 5, 6, 7, 8, 9$.
Notes:
$x$ is always a natural positive number ($x > 0$). It doesn't matter what happens for other values of $x$ (greater than the ones given).
- I am looking for a easy way, as I don't know / I don't have / I have no experience with math related software.
- Also for a polynomial (or similar simple) function, as my mathematical background is quite limited, so I don't know any gamma, delta or other functions, series, etc.
- This quest is simply for recreation, to show friends how there are different solutions to the problems of the type: "Find the next term in this succession"
polynomials
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am looking for an easy way (formula or algorithm) to create a polynomial function that gives the arbitrary preset output for the first values of x. For instance, the desired output can be $y = 1, 2, 3, 4, 5, 6, 100$ for $x = 1, 2, 3, 4, 5, 6, 7$. I can create one of the many functions by hand as:
$y = x + (x-1)(x-2)(x-3)(x-4)(x-5)(x-6)cdot frac93720.$
But for other desired outputs it is really painstaking. For example, I am working now with the desired output $y = 2, 10, 12, 16, 17, 18, 19, 200, 300$ when $x = 1, 2, 3, 4, 5, 6, 7, 8, 9$.
Notes:
$x$ is always a natural positive number ($x > 0$). It doesn't matter what happens for other values of $x$ (greater than the ones given).
- I am looking for a easy way, as I don't know / I don't have / I have no experience with math related software.
- Also for a polynomial (or similar simple) function, as my mathematical background is quite limited, so I don't know any gamma, delta or other functions, series, etc.
- This quest is simply for recreation, to show friends how there are different solutions to the problems of the type: "Find the next term in this succession"
polynomials
polynomials
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 58 mins ago
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Leonardo
1163
1163
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Leonardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
Look-up "Lagrange interpolation"
– Gabriel Romon
1 hour ago
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
1 hour ago
add a comment |Â
5
Look-up "Lagrange interpolation"
– Gabriel Romon
1 hour ago
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
1 hour ago
5
5
Look-up "Lagrange interpolation"
– Gabriel Romon
1 hour ago
Look-up "Lagrange interpolation"
– Gabriel Romon
1 hour ago
1
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
1 hour ago
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
As mentioned in a comment, the key is "Lagrange Interpolation". (See, for instance, Wikipedia or MathWorld.) The idea is straightforward: Build a polynomial out of parts, most of which go away with each input, then make the last part do what it needs to do.
Suppose you want the three (distinct) inputs $a$, $b$, $c$ to give the three outputs $p$, $q$, $r$. The polynomial you want has the form
$$h(x-b)(x-c) + j(x-c)(x-a) + k(x-a)(x-b) tag$star$$$
where $h$, $j$, $k$ are some as-yet-undetermined constants.
When $x=a$, two terms of $(star)$ vanish, leaving $h(a-b)(a-c)$; likewise, $x=b$ yields $j(b-c)(b-a)$, while $x=c$ yields $k(c-a)(c-b)$. So, just choose $h$, $j$, $k$ to give the outputs you desire:
$$beginalign
h(a-b)(a-c) = p qquadtoqquad h = fracp(a-b)(a-c) \[4pt]
j(b-c)(b-a) = q qquadtoqquad ,j = fracq(b-c)(b-a) \[4pt]
k(c-a)(c-b) = r qquadtoqquad k = fracr(c-a)(c-b)
endalign$$
Thus, we can re-write $(star)$ informally as
$requirecancel$
$$p;fraccancel(x-a)(x-b)(x-c)cancel(a-a)(a-b)(a-c)
;+;q;frac(x-a)cancel(x-b)(x-c)(b-a)cancel(b-b))(b-c)
;+;r;frac(x-a)(x-b)cancel(x-c)(c-a)(c-b)cancel(c-c) tag$starstar$$$
Clearly, this kind of thing can be extended to any number of inputs and outputs.
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
add a comment |Â
up vote
1
down vote
As Gabriel Romon commented: Lagrange interpolation does the trick.
The polynomials form a vector space (which works very similar to the 3D coordinate space) where the coefficients work as coordinates and the monomials including $x^0=1$ as orthogonal standard base. The Lagrange polynomials form another one. They are constructed from your given sampling points ($x$-values). The nice thing is that each Lagrange polynomial is zero in all but one sampling points. And in this sampling point it has the value $1$. So you can multiply each of the Lagrange polynomials with the function value at the sampling point where it has a nonzero value and sum over all these polynomials.
This looks as easy as
$$
y = sum_i=1^n y_i cdot ell_i(x).
$$
As you can see there is no $x_i$ in this formula any more. This makes it possible to precompute the Lagrange polynomials $ell_i$ and solve all your problems together in a secound step, as long as all functions are defined using the same sampling points.
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
As mentioned in a comment, the key is "Lagrange Interpolation". (See, for instance, Wikipedia or MathWorld.) The idea is straightforward: Build a polynomial out of parts, most of which go away with each input, then make the last part do what it needs to do.
Suppose you want the three (distinct) inputs $a$, $b$, $c$ to give the three outputs $p$, $q$, $r$. The polynomial you want has the form
$$h(x-b)(x-c) + j(x-c)(x-a) + k(x-a)(x-b) tag$star$$$
where $h$, $j$, $k$ are some as-yet-undetermined constants.
When $x=a$, two terms of $(star)$ vanish, leaving $h(a-b)(a-c)$; likewise, $x=b$ yields $j(b-c)(b-a)$, while $x=c$ yields $k(c-a)(c-b)$. So, just choose $h$, $j$, $k$ to give the outputs you desire:
$$beginalign
h(a-b)(a-c) = p qquadtoqquad h = fracp(a-b)(a-c) \[4pt]
j(b-c)(b-a) = q qquadtoqquad ,j = fracq(b-c)(b-a) \[4pt]
k(c-a)(c-b) = r qquadtoqquad k = fracr(c-a)(c-b)
endalign$$
Thus, we can re-write $(star)$ informally as
$requirecancel$
$$p;fraccancel(x-a)(x-b)(x-c)cancel(a-a)(a-b)(a-c)
;+;q;frac(x-a)cancel(x-b)(x-c)(b-a)cancel(b-b))(b-c)
;+;r;frac(x-a)(x-b)cancel(x-c)(c-a)(c-b)cancel(c-c) tag$starstar$$$
Clearly, this kind of thing can be extended to any number of inputs and outputs.
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
add a comment |Â
up vote
2
down vote
As mentioned in a comment, the key is "Lagrange Interpolation". (See, for instance, Wikipedia or MathWorld.) The idea is straightforward: Build a polynomial out of parts, most of which go away with each input, then make the last part do what it needs to do.
Suppose you want the three (distinct) inputs $a$, $b$, $c$ to give the three outputs $p$, $q$, $r$. The polynomial you want has the form
$$h(x-b)(x-c) + j(x-c)(x-a) + k(x-a)(x-b) tag$star$$$
where $h$, $j$, $k$ are some as-yet-undetermined constants.
When $x=a$, two terms of $(star)$ vanish, leaving $h(a-b)(a-c)$; likewise, $x=b$ yields $j(b-c)(b-a)$, while $x=c$ yields $k(c-a)(c-b)$. So, just choose $h$, $j$, $k$ to give the outputs you desire:
$$beginalign
h(a-b)(a-c) = p qquadtoqquad h = fracp(a-b)(a-c) \[4pt]
j(b-c)(b-a) = q qquadtoqquad ,j = fracq(b-c)(b-a) \[4pt]
k(c-a)(c-b) = r qquadtoqquad k = fracr(c-a)(c-b)
endalign$$
Thus, we can re-write $(star)$ informally as
$requirecancel$
$$p;fraccancel(x-a)(x-b)(x-c)cancel(a-a)(a-b)(a-c)
;+;q;frac(x-a)cancel(x-b)(x-c)(b-a)cancel(b-b))(b-c)
;+;r;frac(x-a)(x-b)cancel(x-c)(c-a)(c-b)cancel(c-c) tag$starstar$$$
Clearly, this kind of thing can be extended to any number of inputs and outputs.
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
As mentioned in a comment, the key is "Lagrange Interpolation". (See, for instance, Wikipedia or MathWorld.) The idea is straightforward: Build a polynomial out of parts, most of which go away with each input, then make the last part do what it needs to do.
Suppose you want the three (distinct) inputs $a$, $b$, $c$ to give the three outputs $p$, $q$, $r$. The polynomial you want has the form
$$h(x-b)(x-c) + j(x-c)(x-a) + k(x-a)(x-b) tag$star$$$
where $h$, $j$, $k$ are some as-yet-undetermined constants.
When $x=a$, two terms of $(star)$ vanish, leaving $h(a-b)(a-c)$; likewise, $x=b$ yields $j(b-c)(b-a)$, while $x=c$ yields $k(c-a)(c-b)$. So, just choose $h$, $j$, $k$ to give the outputs you desire:
$$beginalign
h(a-b)(a-c) = p qquadtoqquad h = fracp(a-b)(a-c) \[4pt]
j(b-c)(b-a) = q qquadtoqquad ,j = fracq(b-c)(b-a) \[4pt]
k(c-a)(c-b) = r qquadtoqquad k = fracr(c-a)(c-b)
endalign$$
Thus, we can re-write $(star)$ informally as
$requirecancel$
$$p;fraccancel(x-a)(x-b)(x-c)cancel(a-a)(a-b)(a-c)
;+;q;frac(x-a)cancel(x-b)(x-c)(b-a)cancel(b-b))(b-c)
;+;r;frac(x-a)(x-b)cancel(x-c)(c-a)(c-b)cancel(c-c) tag$starstar$$$
Clearly, this kind of thing can be extended to any number of inputs and outputs.
As mentioned in a comment, the key is "Lagrange Interpolation". (See, for instance, Wikipedia or MathWorld.) The idea is straightforward: Build a polynomial out of parts, most of which go away with each input, then make the last part do what it needs to do.
Suppose you want the three (distinct) inputs $a$, $b$, $c$ to give the three outputs $p$, $q$, $r$. The polynomial you want has the form
$$h(x-b)(x-c) + j(x-c)(x-a) + k(x-a)(x-b) tag$star$$$
where $h$, $j$, $k$ are some as-yet-undetermined constants.
When $x=a$, two terms of $(star)$ vanish, leaving $h(a-b)(a-c)$; likewise, $x=b$ yields $j(b-c)(b-a)$, while $x=c$ yields $k(c-a)(c-b)$. So, just choose $h$, $j$, $k$ to give the outputs you desire:
$$beginalign
h(a-b)(a-c) = p qquadtoqquad h = fracp(a-b)(a-c) \[4pt]
j(b-c)(b-a) = q qquadtoqquad ,j = fracq(b-c)(b-a) \[4pt]
k(c-a)(c-b) = r qquadtoqquad k = fracr(c-a)(c-b)
endalign$$
Thus, we can re-write $(star)$ informally as
$requirecancel$
$$p;fraccancel(x-a)(x-b)(x-c)cancel(a-a)(a-b)(a-c)
;+;q;frac(x-a)cancel(x-b)(x-c)(b-a)cancel(b-b))(b-c)
;+;r;frac(x-a)(x-b)cancel(x-c)(c-a)(c-b)cancel(c-c) tag$starstar$$$
Clearly, this kind of thing can be extended to any number of inputs and outputs.
edited 52 mins ago
answered 57 mins ago


Blue
44.4k868142
44.4k868142
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
add a comment |Â
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
Sweet ! I was struggling trying to understand Lagrange Interpolation in Wikipedia, as suggested by @Gabriel Romon, and you've made it crystal clear.
– Leonardo
45 mins ago
add a comment |Â
up vote
1
down vote
As Gabriel Romon commented: Lagrange interpolation does the trick.
The polynomials form a vector space (which works very similar to the 3D coordinate space) where the coefficients work as coordinates and the monomials including $x^0=1$ as orthogonal standard base. The Lagrange polynomials form another one. They are constructed from your given sampling points ($x$-values). The nice thing is that each Lagrange polynomial is zero in all but one sampling points. And in this sampling point it has the value $1$. So you can multiply each of the Lagrange polynomials with the function value at the sampling point where it has a nonzero value and sum over all these polynomials.
This looks as easy as
$$
y = sum_i=1^n y_i cdot ell_i(x).
$$
As you can see there is no $x_i$ in this formula any more. This makes it possible to precompute the Lagrange polynomials $ell_i$ and solve all your problems together in a secound step, as long as all functions are defined using the same sampling points.
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
add a comment |Â
up vote
1
down vote
As Gabriel Romon commented: Lagrange interpolation does the trick.
The polynomials form a vector space (which works very similar to the 3D coordinate space) where the coefficients work as coordinates and the monomials including $x^0=1$ as orthogonal standard base. The Lagrange polynomials form another one. They are constructed from your given sampling points ($x$-values). The nice thing is that each Lagrange polynomial is zero in all but one sampling points. And in this sampling point it has the value $1$. So you can multiply each of the Lagrange polynomials with the function value at the sampling point where it has a nonzero value and sum over all these polynomials.
This looks as easy as
$$
y = sum_i=1^n y_i cdot ell_i(x).
$$
As you can see there is no $x_i$ in this formula any more. This makes it possible to precompute the Lagrange polynomials $ell_i$ and solve all your problems together in a secound step, as long as all functions are defined using the same sampling points.
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
As Gabriel Romon commented: Lagrange interpolation does the trick.
The polynomials form a vector space (which works very similar to the 3D coordinate space) where the coefficients work as coordinates and the monomials including $x^0=1$ as orthogonal standard base. The Lagrange polynomials form another one. They are constructed from your given sampling points ($x$-values). The nice thing is that each Lagrange polynomial is zero in all but one sampling points. And in this sampling point it has the value $1$. So you can multiply each of the Lagrange polynomials with the function value at the sampling point where it has a nonzero value and sum over all these polynomials.
This looks as easy as
$$
y = sum_i=1^n y_i cdot ell_i(x).
$$
As you can see there is no $x_i$ in this formula any more. This makes it possible to precompute the Lagrange polynomials $ell_i$ and solve all your problems together in a secound step, as long as all functions are defined using the same sampling points.
As Gabriel Romon commented: Lagrange interpolation does the trick.
The polynomials form a vector space (which works very similar to the 3D coordinate space) where the coefficients work as coordinates and the monomials including $x^0=1$ as orthogonal standard base. The Lagrange polynomials form another one. They are constructed from your given sampling points ($x$-values). The nice thing is that each Lagrange polynomial is zero in all but one sampling points. And in this sampling point it has the value $1$. So you can multiply each of the Lagrange polynomials with the function value at the sampling point where it has a nonzero value and sum over all these polynomials.
This looks as easy as
$$
y = sum_i=1^n y_i cdot ell_i(x).
$$
As you can see there is no $x_i$ in this formula any more. This makes it possible to precompute the Lagrange polynomials $ell_i$ and solve all your problems together in a secound step, as long as all functions are defined using the same sampling points.
answered 37 mins ago


Keinstein
39118
39118
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
add a comment |Â
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
That would save a lot of time! A good extension to @Blue answer! Great !
– Leonardo
24 mins ago
add a comment |Â
Leonardo is a new contributor. Be nice, and check out our Code of Conduct.
Leonardo is a new contributor. Be nice, and check out our Code of Conduct.
Leonardo is a new contributor. Be nice, and check out our Code of Conduct.
Leonardo is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2927511%2fhow-to-easily-create-a-polynomial-function-that-gives-a-desired-output%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
5
Look-up "Lagrange interpolation"
– Gabriel Romon
1 hour ago
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
1 hour ago