1

Three days ago, I asked a question about B-Spline Basis fuction here

@Michael E2 given a solution to make the order of interval looks normal

The easiest way would be to sort it afterwards: MapAt[SortBy[Last], piecewisefn, 1], piecewisefn is the result of NBSpline. (Use SortBy[#, Last] & instead of SortBy[Last] if you're using V9 or earlier.)

Trial 1

 sortResult[res_] := MapAt[SortBy[#, Last] &, res, 1] /; res != 0
 sortResult[0] := 0;
 knots={1, 2, 2, 4, 5, 7};
 sortResult[NBSpline[1, 2, u, knots]]

enter image description here

Trial 2

 NBSpline[1, 3, u, {1, 2, 2, 4, 5, 7}]// MapAt[SortBy[#, Last] &, #, 1] &

enter image description here

This time, it gives me a normal order $2 \leq u <4, 4 \leq u <5, 5 \leq u <7$

Question:

How to revise it ? And can someone give me a explanation about this case?

xyz
  • 605
  • 4
  • 38
  • 117
  • Do you get the desired result if you change the last line of Trial 1 to tmp = NBSpline[1, 2, u, knots]; sortResult[tmp]; tmp? – kglr Oct 18 '14 at 07:43
  • @kguler, it didn't sort the $interval$. – xyz Oct 18 '14 at 07:47

1 Answers1

3

I hope I understand your question. I think you are wondering why Trial 1 does not work the same as Trial 2. In that case the answer lies with != or Unequal. The Condition will not match because != does not evaluate when one side is symbolic and the other numeric. Instead you should use:

sortResult[x_ /; x == 0] := 0;
sortResult[res_] := MapAt[SortBy[#, Last] &, res, 1]

The first definition will catch all arguments Equal to zero. See:

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371