2
$\begingroup$

How can I get an equation of the similar shaped curve?

enter image description here

I've tried to get it like y = a + c x^2 + d x^3:

Fit[{{-3, -3}, {0, 3}, {6, 4}}, {1, x^2, x^3}, x]

But it lacks two roots.

I can't use PolynomialFit because of the lack of points.

$\endgroup$
1
  • $\begingroup$ You could use InterpolationInterpolation[{{-3, -3}, {0, 3}, {6, 4}, {-2, 0}, {2, 0}, {4.5, 0}}, InterpolationOrder -> 4], so the curve will go through the points you specify. $\endgroup$ Nov 16, 2013 at 9:59

3 Answers 3

4
$\begingroup$

Another option is put more points at all the critical locations

pts = {{-3, -3}, {-2, 0}, {0, 3}, {3, 0}, {4, -1}, {5, 0}, {6, 4}};
Fit[pts, {1, x, x^2, x^3, x^4}, x]
Show[ListPlot[pts, PlotStyle -> Directive[Red,PointSize[Large]]],Plot[%, {x, -3, 6}]]

Mathematica graphics

You can also try BSplineCurve but you'd have to play with the option more than what I have below.

 Graphics[BSplineCurve[pts, SplineDegree -> 3], Axes -> True]

Mathematica graphics

$\endgroup$
1
1
$\begingroup$

You have three points that will give you three linear equations in three unknown coefficients. Just solve for the coefficients

data = {{-3, -3}, {0, 3}, {6, 4}};

makeEq[{x_, y_}] := y == a + c x^2 + d x^3
Solve[makeEq /@ data]

This will give you a=3, c=-47/108 and d=25/324. The good news is that this is the one and only solution for that model. The bad news is that, sorry, the curve is not like the one you depicted.

EDIT: By re-reading your question it seems that a + c x^2 + d x^3 is just a tentative model and not the actual model you are trying to fit. I guess the fact you get a definite solution here shows that this model is inadequate for a curve passing for those points and with two more real roots. As a matter of fact, the other answer(s) showed a curve modeled by a different polynomial.

Let me add that, the condition to have a relative maximum in x=0 means that the coefficient b has to be zero (since by differentiating the polynomial you get b + something*x = ...). Thus is you wanted a solution in the form of a third degree polynomial passing for the points given in data and with a relative maximum in 0 you are out of luck. You can still get a third degree polynomial passing for those points, with one negative and two positive real roots in the specified intervals, if you let go the condition on the peak. One can be found in this way

makeEq[{x_, y_}] := (y == (x - x0)(x - x1)(x - x2) // Expand)
data = {{-3, -3}, {0, 3}, {6, 4}};
sols=NSolve[makeEq /@ data]

You will get the same solution in different permutations. The third degree poly with one (negative) real solution in [-3,0] and two (real) positive solutions in [0,6] is given by

Expand[(x - x0)(x - x1)(x - x2) /. sols][[1]]
x^3 + 3.2037 x^2 - 16.6111 x + 3

It goes through (0,3) but it has no stationary point there.

$\endgroup$
1
$\begingroup$

Using InterpolatingPolynomial:

InterpolatingPolynomial[{{-3, -3}, {-2, 0}, {0, {3, 0}}, {4, {-1, 0}}, {6, 4}}, x] // Expand 
3 - (3653 x^2)/5292 + (2477 x^3)/31752 + (13 x^4)/784 - (
 17 x^5)/5292 + (17 x^6)/63504
p = Plot[%, {x, -3, 6}, PlotStyle -> Thickness[0.0035], 
   ColorFunction -> "BlueGreenYellow"];

pp = ListPlot[{{-3, -3}, {-2, 0}, {0, 3}, {2.7, 0}, {4.99, 
     0}, {4, -1}, {6, 4}}, 
   PlotStyle -> Directive[Red, PointSize[Large]]];

Show[p, pp]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.