0
|
6098 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

# Why do I get Null when using my function?

Posted 10 years ago
 I've built my own function, but using it returns me Null which should not be,the function which I have built is as follows RCL[sup_, inf_, alpha_, lista_] := Module[{down, up, w, sel}, down = Apply[Times, sup] - 0.4*(Apply[Times, sup] - Apply[Times, inf]); up = Apply[Times, sup]; Table[ If[ down <= Apply[Times, lista[[w]]] <= up, lista[[w]]], {w, 1, Length[lista]}] ]  When used with the following data arises the problem that said, I hope someone can help me to understand this behavior listin={{65, 80}, {65, 80}, {40, 40}, {40, 40}, {40, 40}, {25, 30}, {25,30}, {25, 30}, {25, 30}, {25, 30}}; RCL[{65, 80}, {25, 30}, 0.4, listin] Out[2]:={{65, 80}, {65, 80}, Null, Null, Null, Null, Null, Null, Null, Null}  Thanks in advance
5 Replies
Sort By:
Posted 10 years ago
 Null is what you get from your If statement when the criterion isn't satisfied. In[3]:= If[2 > 3, "yes"] // InputForm Out[3]//InputForm= Null 
Posted 10 years ago
 Hi Frank, thanks for your quick response, now my question is, how do I do this function unless you get the Null? I I thought that was the way to do it, I hope you can help me, greetings
Posted 10 years ago
 You could use Select to get rid of the Nulls In[7]:= Select[{2, Null, 3, 4, Null}, # =!= Null &] Out[7]= {2, 3, 4} or use Select instead of If to get the results you want, which is probably the better approach. In[8]:= Select[Range[5], 2 <= # <= 4 &] Out[8]= {2, 3, 4} 
Posted 10 years ago
 In[9]:= p = Partition[Range[10], 2] Out[9]= {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}} In[15]:= Select[p, 3 <= Times @@ # <= 45 &] Out[15]= {{3, 4}, {5, 6}} 
Posted 10 years ago
 Thank you Frank,Ii'm going to use Select as you suggested, thanks again,look after ,greetings