Interpolation with boundary conditions

I'm working on a sales projection, trying to create some flexibility in handle the forecast using locators.

The toy code is something like this:

DynamicModule[{pts={{1,1},{2,1}}}
,LocatorPane[
Dynamic[pts]
,Dynamic@Plot[Piecewise[{{InterpolatingPolynomial[{{0,1},Sequence@@pts,{3,5}},x],x<3},{5,x>3}}],{x,0,5},PlotRange->{{0,5},{0,6}}]
]
]


Where I can change the locators position in order to change the curve.

The question is, assuming my plot functions as f[x]

1. How to define f'[3]=0 to don't get the slop break in {3,5}?
2. How to define f'[0]>0 to don't get a initial down slope?

So I could control the polinomial order to get these conditions met, still using locators.

Maybe using NDSolve together with LinearModelFit? Or is there a simpler way?

Update

The first condition was solved by @kguler and @belisarius. Tks to both.

Some clue for the second?

-
For (1) you can use {3, 5, 0} instead of {3,5}. For (20, changing the first point {0,1} to {0,1,1} controls the slope at x=0 but, it seems, patterns like {0,1,_Positive} don't work.. – kglr Jan 24 '13 at 1:47
see my edited answer – Dr. belisarius Jan 24 '13 at 1:59

add 0 valued derivatives at {3,5} and a slider for controlling the derivative at 0:

DynamicModule[{pts = {{1, 1}, {2, 1}}, d},
Column@{
Slider[Dynamic[d], {0, 3}],
LocatorPane[Dynamic[pts],
Dynamic@
Plot[Piecewise[{{InterpolatingPolynomial[{{0, 1, d, 0},
Sequence @@ pts, {3, 5, 0, 0, 0}}, x], x < 3}, {5, x > 3}}],
{x, 0, 5}, PlotRange -> {{0, 5}, {0, 6}}]]}]


Edit

To get a positive derivative at x=0, you may also dynamically add more locators like this:

DynamicModule[{pts = {{1, 1}, {2, 1}}},
LocatorPane[Dynamic[pts],
Dynamic@Plot[Piecewise[{{InterpolatingPolynomial[{{0, 1},
Sequence @@ Sort@pts, {3, 5, 0, 0, 0}}, x], x < 3}, {5, x > 3}}], {x, 0, 5},
PlotRange -> {{0, 5}, {0, 6}}],  LocatorAutoCreate -> True]]


-
Very interesting and simple!.. I get a even better effect with {3, 5, 0, 0} tks +1 – Murta Jan 24 '13 at 1:52

A possible way by using one curve to get the derivative, then substituting into another one:

DynamicModule[{pts = {{1, 1}, {2, 1}}, func},
LocatorPane[Dynamic[pts],
Dynamic[
Plot[{
Piecewise[{{(func = Interpolation[{
{{0}, 1},
{{pts[[1, 1]]}, pts[[1, 2]]},
{{pts[[2, 1]]}, pts[[2, 2]]},
{{3}, 5, 0}
}])[x], x < 3}, {5, x > 3}}],
Piecewise[{{Interpolation[{
{{0}, 1, If[# < 0, 0, #] &[func'[0]]},
{{pts[[1, 1]]}, pts[[1, 2]], func'[pts[[1, 1]]]},
{{pts[[2, 1]]}, pts[[2, 2]], func'[pts[[2, 1]]]},
{{3}, 5, 0}
}][x], x < 3}, {5, x > 3}}]
}, {x, 0, 5}, PlotRange -> {{0, 5}, {0, 6}},
PlotStyle -> {GrayLevel[.5], Red}]
]]]


For real applications, only plot the curve needed:

DynamicModule[{pts = {{1, 1}, {2, 1}}, func},
LocatorPane[Dynamic[pts],
DynamicWrapper[
Dynamic@Plot[Piecewise[{{Interpolation[{
{{0}, 1, If[# < 0, 0, #] &[func'[0]]},
{{pts[[1, 1]]}, pts[[1, 2]], func'[pts[[1, 1]]]},
{{pts[[2, 1]]}, pts[[2, 2]], func'[pts[[2, 1]]]},
{{3}, 5, 0}
}][x], x < 3}, {5, x > 3}}], {x, 0, 5},
PlotRange -> {{0, 5}, {0, 6}} ],
func = Interpolation[{
{{0}, 1},
{{pts[[1, 1]]}, pts[[1, 2]]},
{{pts[[2, 1]]}, pts[[2, 2]]},
{{3}, 5, 0}
}]
]]]


-

Adding values for the first, second, third... derivatives at x=0 and x=3:

 DynamicModule[{pts = {{1, 1}, {2, 1}}},
LocatorPane[Dynamic[pts], Dynamic@Plot[
Piecewise[{{InterpolatingPolynomial[{{0, 1, 0, 1},
Sequence @@ pts, {3, 5, 0, 1}}, x], x < 3}, {5, x > 3}}],
{x, 0, 5}, PlotRange -> {{0, 5}, {0, 6}}]]]


Update: Tie the first/second/... derivatives at x=0 and x=3 to the locator values; for example:

DynamicModule[{pts = {{1, 1}, {2, 1}}},
LocatorPane[Dynamic[pts],  Dynamic@Plot[
Piecewise[{{InterpolatingPolynomial[{{0, 1, 0, Abs@pts[[1, 2]]},
Sequence @@ pts, {3, 5, 0, -Abs[pts[[2, 2]]]}}, x],   x < 3},
{5, x > 3}}], {x, 0, 5}, PlotRange -> {{0, 5}, {0, 6}}]]]


-