Message Boards Message Boards

0
|
15784 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Error: Nonatomic expression expected?

Posted 9 years ago

I am following this topic in order to get my resuls. This code should be quite general but I get a really basic error which I don't understand how...

So my code is:

bezier[pts_List] := 
 With[{n = Length[pts] - 1}, 
  Evaluate@Sum[
     Binomial[n, i] (1 - #)^(n - i) #^i pts[[i + 1]], {i, 0, n}] &]
yfn[pts_] := 
 Piecewise[
  Function[pp, 
    Select[y /. 
         N@Solve[Rationalize[
            bezier[pp][t] == {x, y} && pp[[1, 1]] <= x <= pp[[-1, 1]],
             0], {y}, {t}, Reals, Method -> Reduce] /. 
        Less -> LessEqual // Expand, 
      Chop[# - pp[[1, 2]] /. x -> pp[[1, 1]]] == 0 &] /. 
     ConditionalExpression -> 
      Sequence] /@ (If[Length@Last@# == 1, Most@#, #] &@
     Partition[pts, 4, 3, 1, {}]), Indeterminate]

and

btm = {{100., -0.0039549}, {1250/
    13, -0.465743}, {91.9629, -0.627156}, {87.7691, -0.725599}, \
{83.5791, -0.908002}, {79.3881, -1.06942}, {75.198, -1.25182}, \
{71.0079, -1.43422}, {66.8206, -1.67959}, {62.6305, -1.862}, \
{58.4423, -2.08638}, {54.2522, -2.26878}, {50.0621, -2.45119}, \
{45.8721, -2.63359}, {41.6802, -2.77401}, {37.491, -2.97741}, {33.3, \
-3.13882}, {29.1099, -3.32122}, {24.9208, -3.52462}, {20.7298, \
-3.68603}, {18.6366, -3.81921}, {16.5415, -3.91041}, {14.4465, \
-4.00161}, {12.3506, -4.07183}, {10.2492, -4.0161}, {8.14138, \
-3.81344}, {7.12596, -3.62981}, {6.02085, -3.31691}, {5.10096, \
-2.97019}, {3.88485, -2.46356}, {2.86923, -1.98654}, {1.73975, \
-1.40031}, {0.721154, -0.6}, {0.238654, -0.231058}, {0.00972115, \
-0.0211058}, {0, -0.00396087}}

What I would like to get is yfn[btm] but I get an error saying Nonatomic expression expected at position 1 in Select[y,Chop[#1-Part[<<3>>]/. x->{<<4>>}[[1,1]]]==0&]. >>

I don't know why this happens nor do I know how to get rid of that error. Please help.

POSTED BY: Mitja Jan?i?
6 Replies
Posted 9 years ago

I thought it was just me that couldn't understand your code.

Unfortunately I tossed all the stuff I did the moment I posted the message. But here is a quick example of the method I think I used.

mySolve[pp_, t_, x_, y_] := (
  qq = Solve[Rationalize[bezier[pp][t] == {x,y} && pp[[1,1]]<=x<=pp[[-1,1]],0],{y},{t},Reals,Method->Reduce]; 
  Print["{pp,t,x,y,qq}=", {pp, t, x, y, qq}];
  qq); 
bezier[pts_List] := With[{n = Length[pts]-1}, Evaluate@Sum[Binomial[n,i] (1-#)^(n-i) #^i pts[[i+1]],{i,0,n}]&];
yfn[pts_] := Piecewise[Function[pp, Select[y /. N@mySolve[pp, t, x, y] /. Less -> LessEqual // Expand,
   Chop[# - pp[[1, 2]] /. x -> pp[[1, 1]]] == 0 &] /. ConditionalExpression -> Sequence] /@
   (If[Length@Last@# == 1, Most@#, #] &@Partition[pts, 4, 3, 1, {}]), Indeterminate];
btm = {{100., -0.0039549}, {1250/13, -0.465743}, {91.9629, -0.627156}, {87.7691, -0.725599},
   {83.5791, -0.908002}, {79.3881, -1.06942}, {75.198, -1.25182}, {71.0079, -1.43422}, {66.8206, -1.67959},
   {62.6305, -1.862}, {58.4423, -2.08638}, {54.2522, -2.26878}, {50.0621, -2.45119}, {45.8721, -2.63359},
   {41.6802, -2.77401}, {37.491, -2.97741}, {33.3, -3.13882}, {29.1099, -3.32122}, {24.9208, -3.52462},
   {20.7298, -3.68603}, {18.6366, -3.81921}, {16.5415, -3.91041}, {14.4465, -4.00161}, {12.3506, -4.07183},
   {10.2492, -4.0161}, {8.14138, -3.81344}, {7.12596, -3.62981}, {6.02085, -3.31691}, {5.10096, -2.97019},
   {3.88485, -2.46356}, {2.86923, -1.98654}, {1.73975, -1.40031}, {0.721154, -0.6}, {0.238654, -0.231058},
   {0.00972115, -0.0211058}, {0, -0.00396087}};
yfn[btm]

which gives output

{pp,t,x,y,qq}={{{100.,-0.0039549},{1250/13,-0.465743},{91.9629,-0.627156},{87.7691,-0.725599}},t,x,y,{}}

Select::normal: Nonatomic expression expected at position 1 in Select[y,Chop[#1-Part[<<3>>]/. x->{<<4>>}[[1,1]]]==0&]. >>

{pp,t,x,y,qq}={{{87.7691,-0.725599},{83.5791,-0.908002},{79.3881,-1.06942},{75.198,-1.25182}},t,x,y,{}}

Select::normal: Nonatomic expression expected at position 1 in Select[y,Chop[#1-Part[<<3>>]/. x->{<<4>>}[[1,1]]]==0&]. >>

 etc, etc, etc

So, based on the error messages I concluded that y wasn't a list. y appeared to be coming from Solve. I created mySolve and passed it every argument that it was using. Inside mySolve I saved the result returned from Solve, printed diagnostics and then returned the result from Solve.

And the diagnostics seem to indicate that qq, which will become y, isn't a list. And that is what the error messages are complaining about.

This doesn't quite look like what I remember from yesterday, so look through all this and see if you can spot any of my mistakes. And try this on your data that works

POSTED BY: Bill Simpson
Posted 9 years ago

One error message you are getting

Select::normal: Nonatomic expression expected at position 1 in Select[y,Chop[#1-Part[<<3>>]/. x->{<<4>>}[[1,1]]]==0&]. >>

says that Select expects to be given a first argument that is a list.

You are giving select just the symbol y which is not a list.

Your code expands at run time to be

{Select[y,Chop[Slot[<<1>>]+Times[<<2>>]/. x->Part[<<3>>]]==0&],
 Select[y,Chop[Slot[<<1>>]+Times[<<2>>]/. x->Part[<<3>>]]==0&],
 Select[y,Chop[Slot[<<1>>]+Times[<<2>>]/. x->Part[<<3>>]]==0&],
 <<7>>,
 Select[y,Chop[Slot[<<1>>]+Times[<<2>>]/. x->Part[<<3>>]]==0&],
 Select[y,Chop[Slot[<<1>>]+Times[<<2>>]/. x->Part[<<3>>]]==0&]}

and your next error message says that this is not a list of pairs when given to piecewise, but perhaps that will be resolved when the Select is fixed.

When I disentangle all your /. so I can insert some diagnostic information it appears that Solve is returning an empty list twelve times.

If by brute force I substitute {{y->3}} whenever I find that Solve has returned an empty list then at least the error messages about Select disappear, but this still isn't all that is needed.

SO my conclusion is that under some circumstances your Solve is not finding any solutions and that your code is not prepared to deal with that circumstance.

Try giving it a fake dataset btm that ensures you will get a solution for every pair and see if the code works. Then give it a fake dataset with a single pair that will not get a solution.

Does that help point you where you need to start looking?

POSTED BY: Bill Simpson

Could you PLEASE publish that code where you disentangled all /.? Because the thing is, this is not my code and it is basically impossible for me to understand it - my knowledge of Mathematica is far below that. I simply copied it from the link I provided and I get an error (NOTE: I have a different set of data - different btm points where this code runs really smoothly therefore I assume these points in OP have some kind of faulty. If you believe this would help finding the error I can publish a working example.)

POSTED BY: Mitja Jan?i?

Anybody? Anything? :/

POSTED BY: Mitja Jan?i?
Posted 9 years ago

Please edit your post to include the contents of the matrix named 'data' and explain the two different assignments you have to 'btm'. Given that information it might be possible to answer your question or at least to be able to ask the next question.

Thank you

POSTED BY: Bill Simpson

True, there was a typo I didn't notice before posting. I have edited the OP and things should be clear now.

POSTED BY: Mitja Jan?i?
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract