2
$\begingroup$

I would like to add constraints on a model and its derivatives and then use FindFit to fit some parameters. An example is below:

modelt[a_?NumberQ, k_?NumberQ] := (modelt[a, k] = 
First[x /.NDSolve[{x'[t] == (1/2)*y[t]*(Sin[x[t] + a] + Cos[x[t] + a]), 
y'[t] == k Sin[x[t]], x[0] == Pi/2, y[0] == 1/2}, {x,  y}, {t, 0, 1000}]])

FindFit[{1000, Pi/6}, {modelt[a, k][t]}, {a, k}, t, 
 Method -> {NMinimize, Method -> "SimulatedAnnealing"}]

Is there a way to add constraints to FindFit such as x'[1000] == 0, x''[1000] < 0,. How do you go about doing this? Thanks!

$\endgroup$
3
  • 2
    $\begingroup$ Formally, you can add additional constraints to second argument of FindFit (see help). And because x[t] is modelt[a, k][t] you can write smth. like FindFit[{1000, Pi/6}, {modelt[a, k][t], modelt[a, k]'[1000]==0,modelt[a, k]''[1000]<0}, {a, k}, t, Method -> {NMinimize, Method -> "SimulatedAnnealing"}]. $\endgroup$
    – Alx
    Commented Oct 16, 2019 at 12:25
  • $\begingroup$ Hey @Alx ! Thanks for the help, you were correct in your suggestion! I will add it as a solution. $\endgroup$
    – Cameron F.
    Commented Oct 17, 2019 at 9:02
  • $\begingroup$ @Alx, I have started working on combining your solution with another popular question on FindFit but have come to a bit of a roadblock, if you have a second let me know! Here is the link to it: mathematica.stackexchange.com/questions/208054/… $\endgroup$
    – Cameron F.
    Commented Oct 17, 2019 at 9:55

1 Answer 1

1
$\begingroup$

As @Alx suggested in the comments, adding constraints onto the model such as modelt[a, k]'[1000]==0,modelt[a, k]''[1000]<0 was the correct method. Thanks to him!

$\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.