2
$\begingroup$

I've tried to use FindRoot to find the roots of a vector interpolation function,

but Mathematica is clearly giving me the wrong answer.

What's going on here?

Here is my code to reproduce the problem.

Thanks :)

Remove["Global`*"] // Quiet;
dat = Table[{t, {2  Cos[t], Sin[t]}}, {t, 0, 2 Pi, 0.5}];
intp = Interpolation[dat, Method -> "Hermite", 
   InterpolationOrder -> 3];
Plot[intp[t][[1]], {t, 0, 2}]
FindRoot[intp[t][[1]] == 0, {t, 0.5, 0, 2}]

FindRoot fails?

$\endgroup$
1

1 Answer 1

5
$\begingroup$

Method-1

  • replace [[ ]],Part with Indexed.
FindRoot[Indexed[intp[t], 1] == 0, {t, 0.5, 0, 2}]

{t -> 1.57089}

Method-2

  • intp[t][[1]] return t,that is why the result not right. We can also use
F[t_?NumericQ] := intp[t][[1]];
FindRoot[F[t] == 0, {t, 0.5, 0, 2}]

{t -> 1.57089}

since for t belong to numeric number, intp[t][[1]] return the numeric first part of intp[t].

Method-3

  • Using Evaluated -> False to prevent intp[t][[1]] return t.
FindRoot[intp[t][[1]] == 0, {t, 0.5, 0, 2}, Evaluated -> False]

{t -> 1.57089}

$\endgroup$
2
  • $\begingroup$ Thank you very much for the explanation. Could you please explain a bit more about why my code using Part is incorrect? $\endgroup$
    – xinxin guo
    Commented May 20 at 0:56
  • $\begingroup$ You explained it so clearly! Thanks, have a nicde day :) $\endgroup$
    – xinxin guo
    Commented May 20 at 1:09

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.