Message Boards Message Boards

0
|
3450 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Help with Null

Posted 9 years ago

I would like to ask for your help with the next question i have, my function diamond works as i hope,see you Here is malla

malla={{100, 0, 0, 0, 0, 0, 100}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 
  0}, {0, 0, 0, 102, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 
  0, 0}, {100, 0, 0, 0, 0, 0, 100}};

Next the function diamond

diamond[main_, gx_, gy_, grider_] := 
 Module[{grid = grider, last, half, b, c, g, h, d, a, e, f, i, top, 
   left, botton, right},
  last = Length[grid] - 1;
  half = Ceiling[last/2.];
  b = {gx, gy};
  c = {gx + last, gy};
  g = {gx, gy + last};
  h = {gx + last, gy + last};
  d = {gx + half, gy + half}; (* midpoint*)
  (* extreme corners*)
  If[gy - half >= 0 , a = {gx + half, gy - half}, a = Null];
  If[gx - half >= 0, e = {gx - half, gy + half}, e = Null];
  If[gx + last + half < Length[main], 
   f = {gx + last + half, gy + half}, f = Null];
  If[gy + last + half < Length[main], 
   i = {gx + half, gy + last + half}, i = Null];
  {a, b, c, d, e, f, g, h, i}]

Test of diamond function

diamond[malla, 1, 1, malla]

the results that throws the diamond function are the ones I hope, the problem arises when I try to use the following function called average,

average[a_, b_, c_, d_, main_] := Module[{total = 0, count = 0, x},
  If[a != Null, x = main[[a[[1]], a[[2]]]]; 
   If[x != 0, total = total + x ; count++]];
  If[b != Null, x = main[[b[[1]], b[[2]]]]; 
   If[x != 0, total = total + x ; count++]];
  If[c != Null, x = main[[c[[1]], c[[2]]]]; 
   If[x != 0, total = total + x ; count++]];
  If[d != Null, x = main[[d[[1]], d[[2]]]]; 
   If[x != 0, total = total + x ; count++]];
  Ceiling[total/N[count]]
  ]

When test average with the following parameters,Mathematica returns indeterminations which is something that I don't want to, look

average[Null, {1, 1}, {7, 1}, {4, 4},malla]

I think that the problem is. what because Mathematica does not make the comparison of {1,1 } ! =Null,returning only the same input i.e. {1,1 } != Null, Is there any way make that run the average function?, if anyone can help me thank you it is in advance, good night all.

POSTED BY: Luis Ledesma
2 Replies
Posted 9 years ago

Gianluca Gorni, thank you very much for your help, with the solution that gave me it solved my problem, that's what I needed.

Greetings Luis Ledesma :)

POSTED BY: Luis Ledesma

Try writing x =!= y (UnsameQ) instead of x != y (Unequal).

POSTED BY: Gianluca Gorni
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