Message Boards Message Boards

0
|
2376 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why does an unused expression change the result?

Posted 2 years ago

https://www.wolframcloud.com/obj/68428eed-0e9a-411b-a054-03d3c6aab0f7

On this, about halfway down, I define this gsum2 function....

gsum2[sort_,x_,y_,z_,b_]:=(
(*wells is passed as a function, this sorts the wells according to the current point*)
w=sort[x,y,z]; (* Print["at:",{x,y,z},":",w];*)
(* Add the deltas from well 1-9 (skip last which is furthest/closest) *)
r=gadd[Sum[gspot[w[[i]][[1]],w[[i]][[2]],w[[i]][[3]],x,y,z,b],{i,9}],{x,y,z}];
(*Finally, adjust the displaced spatial point by the last well... *)
fin = gadd[gspot[w[[10]][[1]],w[[10]][[2]],w[[10]][[3]],r[[1]],r[[2]],r[[3]],b],{x,y,z}];
(*fin is just the final delta *)
(*Print["r:", r, " del:", del , " fin:", fin, " xyz:",{x,y,z}, " W:", w[[10]]];*)
r
);

If I have fin= uncommented, then the result 'r' is different.
I actually want the final result to be 'fin', but it's not working right for some reason... and doing the expression breaks R, which otherwise is exactly the 'gsum' function above it essentially.

I just want to do the sum of 1-9 instead of all 10, then take that point and do the 10'th 'gspot' calculation.

'gspot' is the gravity displacement for that spot; that is, for a point, and a gravity well position, take the delta, and displace it an amount according to the relative position to that well. (I think I'm wandering into TMI territory)

POSTED BY: J Decker
3 Replies

I don't know exactly what you are trying to do but I notice at first glance that you pass r to a function that changes r in function gspot. This seems dangerous to me. If you intended to do some form of recursion, you need to debug that, otherwise, I think you need to use Module[] to localize your variables. Using Module is always a good idea to keep these types of interactions to a minimum.

Did you intend to pass r to a function that alters r? Do you need help debugging that or was it an unintended bug?

Regards,

Neil

POSTED BY: Neil Singer
Posted 2 years ago

I didn't know that there was ever a modification of an existing value; that everything should be a new object with values....

POSTED BY: J Decker
Posted 2 years ago

Oh I see it now, there is a 'r' referenced internally (again) with another thing I get it. that's not even itself used except when I was trying to debug...

POSTED BY: J Decker
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