1

I've got a bit of a weird set of conditions I need to fit a curve to. I've tried looking it up elsewhere but I'm not even sure I'm using the right lingo. Any help is much appreciated.

I'm trying to fit a polynomial curve to a set of four points. Three of the points are known, but the fourth one is a little tricky. I have the x value for the maximum y value, but I don't know what the maximum y value is. For example, let's say there are known points at (0,0), (1,1), and (4,0). The maximum y value is at x=3 so the fourth point is (3, ymax). How would I fit a 4th order polynomial curve to those conditions? Thanks in advance.

2 Answers2

4

Actually it is possible since you require the y value at x=3 should be maximum. So, a degree 4 polynomial has 5 coefficients to be determined and you have the following equations:

y(0) = 0
y(1) = 1
y(4) = 0
dy/dx(3) = 0 (first derivative at x=3 should be 0)
d2y/dx2(3) < 0 (2nd derivative at x=3 should be negative)

So, pick any negative value for d2y/dx2 at x=3 and solve the 5 linear equations and you will get one degree 4 polynomial. Note that the y value at x=3 obtained this way is only a local maximum, not a global maximum.

fang
  • 3,473
  • 1
  • 13
  • 19
2

Filling in the algebra from @fang's answer (a little elementary calculus, some algebra, and some linear algebra):

y = a+b*x+c*x^2+d*x^3+e*x^4

y(0) = 0 -> a=0

Set a=0 for the rest of the computations.

y(1) = 1 -> b+c+d+e = 1
y(4) = 0 -> 4*b+16*c+64*d+256*e=0
dy/dx(3)=0 ->
    b+2*x*c+3*x^2*d+4*x^3*e=0 ->
    b+6*c+27*d+108*e=0
d2y/dx2(3)<0 = 2*c+6*d*x+12*e*x^2 < 0 
             = 2*c+18*d+108*e < 0

Pick a negative value V for the last expression, say -1:

V <- -1
A <- matrix(c(1, 1, 1,  1,
              4,16,64,256,
              1, 6,27,108,
              0, 2,18,108),
            ncol=4,byrow=TRUE)
b <- c(1,0,0,V)
(p <- solve(A,b))
## [1]  2.6400000 -2.4200000  0.8933333 -0.1133333

x <- seq(-0.5,5,length=101)
m <- model.matrix(~poly(x,degree=4,raw=TRUE))
y <- m %*% c(0,p)

Plot results:

par(las=1,bty="l")
plot(x,y,type="l")
points(c(0,1,4),c(0,1,0))
abline(v=3,lty=2)

enter image description here

Picking a larger magnitude (more negative) value for V will make the solution more sharply peaked at y=3.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453