Group Abstract Group Abstract

Message Boards Message Boards

1
|
7.2K Views
|
9 Replies
|
3 Total Likes
View groups...
Share
Share this post:

A problem of FindRoot with BSplineFunction

Posted 4 years ago

Hi! I have a problem like the following,

data={{-1,2.9},{0.5,3.6},{1.0,5.5},{1.5,-4.2},{2.0,3.5}};
f=BSplineFunction[data];
FindRoot[f[t][[1]]==0,{t,0,0.2}]

However, FindRoot firstly wokes like f[t][[1]]=t, but not to find the root of the first argument of f[t]. How can I get the root which one I wanted? Thanks!

POSTED BY: Jianhua Yang
9 Replies

I have made my own implementation of BSplineFunction, to make it more usable:

BSplineCurveFunction[pts_?MatrixQ] := 
  Module[{knots, deg}, 
   knots = Rationalize@BSplineFunction[pts][[6, 1]]; 
   deg = BSplineFunction[pts][[3, 1]];
   Apply[Function, 
    List@
     Sum[
      pts[[i + 1]] BSplineBasis[{deg, knots}, i, #], {i, 0, 
       Length[pts] - 1}]]];
data = {{-1, 2.9}, {0.5, 3.6}, {1.0, 5.5}, {1.5, -4.2}, {2.0, 3.5}};
g[t_] = BSplineCurveFunction[data][t][[1]]
FindRoot[g[t] == 0, {t, 0, 0.2}]
POSTED BY: Gianluca Gorni
Posted 4 years ago

Interesting implementation, thank you for sharing! Strongly related MMa.SE question with another implementation:

POSTED BY: Alexey Popkov

I may have misunderstood which root you were trying to find. If you want to find the crossing of the x axis, as Henrik understood, then similarly you need to use First instead of Last in the g function above (or use Henrik's approach).

Regards.

POSTED BY: Neil Singer
Posted 4 years ago

It's not important. You two gave me some good ideas to deal with the problem. The key problem is how to find the root of any one component of BSplineFunction such as f[t] with FindRoot. f[t] is a two components function in some sense. Thank you again.

Best regards!

POSTED BY: Jianhua Yang

The key problem is how to find the root of any one component of BSplineFunction ...

Well, you could look for roots of the product of the components:

fi = FunctionInterpolation[Times @@ f[t], {t, 0, 1}]

(Somehow I could not avoid using FunctionInterpolation!) For finding (sort of) all roots in the interval [0, 1] you could try something (ugly) like this:

DeleteDuplicates[N@Round[\[FormalT] /. Quiet@FindRoot[fi[\[FormalT]], {\[FormalT], #}], 1*^-7] & /@ Range[0, 1, .2]]
(*  Out:   {0.1412204`,0.6872917`,0.8855624`}  *)
POSTED BY: Henrik Schachner

Here is one more solution - for me it is the first time I can make use of FunctionInterpolation:

fi = FunctionInterpolation[First[f[t]], {t, 0, 1}];
FindRoot[fi[t], {t, .2}]
POSTED BY: Henrik Schachner
Posted 4 years ago

Thank you! It's a good idea to solve my problem.

POSTED BY: Jianhua Yang
POSTED BY: Neil Singer
Posted 4 years ago
POSTED BY: Jianhua Yang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard