0
$\begingroup$

I am trying to solve for central difference for the following set of points and function;

f[x_, y_] = x + x/(x^2 + y^2);

pnts2 = {{-1.6, 0.4}, {-1.6, 0.6}, {-1.6, 0.8}, {-1.6, 1.}, {-1.6, 
1.2}, {-1.6, 1.4}, {-1.6, 1.6}, {-1.6, 1.8}, {-1.4, 0.4}, {-1.4, 
0.6}, {-1.4, 0.8}, {-1.4, 1.}, {-1.4, 1.2}, {-1.4, 1.4}, {-1.4, 
1.6}, {-1.4, 1.8}, {-1.2, 0.4}, {-1.2, 0.6}, {-1.2, 0.8}, {-1.2, 
1.}, {-1.2, 1.2}, {-1.2, 1.4}, {-1.2, 1.6}, {-1.2, 1.8}, {-1., 
0.4}, {-1., 0.6}, {-1., 0.8}, {-1., 1.}, {-1., 1.2}, {-1., 
1.4}, {-1., 1.6}, {-1., 1.8}, {-0.8, 0.8}, {-0.8, 1.}, {-0.8, 
1.2}, {-0.8, 1.4}, {-0.8, 1.6}, {-0.8, 1.8}, {-0.6, 1.}, {-0.6, 
1.2}, {-0.6, 1.4}, {-0.6, 1.6}, {-0.6, 1.8}, {-0.4, 1.}, {-0.4, 
1.2}, {-0.4, 1.4}, {-0.4, 1.6}, {-0.4, 1.8}, {-0.2, 1.}, {-0.2, 
1.2}, {-0.2, 1.4}, {-0.2, 1.6}, {-0.2, 1.8}, {0., 1.2}, {0., 
1.4}, {0., 1.6}, {0., 1.8}, {0.2, 1.}, {0.2, 1.2}, {0.2, 
1.4}, {0.2, 1.6}, {0.2, 1.8}, {0.4, 1.}, {0.4, 1.2}, {0.4, 
1.4}, {0.4, 1.6}, {0.4, 1.8}, {0.6, 1.}, {0.6, 1.2}, {0.6, 
1.4}, {0.6, 1.6}, {0.6, 1.8}, {0.8, 0.8}, {0.8, 1.}, {0.8, 
1.2}, {0.8, 1.4}, {0.8, 1.6}, {0.8, 1.8}, {1., 0.4}, {1., 
0.6}, {1., 0.8}, {1., 1.}, {1., 1.2}, {1., 1.4}, {1., 1.6}, {1., 
1.8}, {1.2, 0.4}, {1.2, 0.6}, {1.2, 0.8}, {1.2, 1.}, {1.2, 
1.2}, {1.2, 1.4}, {1.2, 1.6}, {1.2, 1.8}, {1.4, 0.4}, {1.4, 
0.6}, {1.4, 0.8}, {1.4, 1.}, {1.4, 1.2}, {1.4, 1.4}, {1.4, 
1.6}, {1.4, 1.8}, {1.6, 0.4}, {1.6, 0.6}, {1.6, 0.8}, {1.6, 
1.}, {1.6, 1.2}, {1.6, 1.4}, {1.6, 1.6}, {1.6, 1.8}, {1.8, 
0.4}, {1.8, 0.6}, {1.8, 0.8}, {1.8, 1.}, {1.8, 1.2}, {1.8, 
1.4}, {1.8, 1.6}, {1.8, 1.8}};

I have coded the formula for central difference as follows;

p[x_, y_] := [(x + .2) + (x + .2)/(((x + .2)^2) + (y^2))];
q[x_, y_] := [(x - .2) + (x - .2)/(((x - .2)^2) + (y^2))];
r[x_, y_] := [x + ((x)/((x^2) + ((y + .2)^2)))];
z[x_, y_] := [x + ((x)/((x^2) + ((y - .2)^2)))];
changeofx = D[f[x, y], x];
changeofy = D[f[x, y], y];
centraldiff = {((p - q)/(2*changeofx)), ((r - z)/(2*changeofy))};
centraldiff @@ pnts2

I thought doing @@@pnt2 after defining each variable would give me a list of point outputs for change of x and y, but it just multiplies it to the entire function instead. How do I get the centraldiff function to take in one point (x,y), from the list defined for pnt2, at a time?

$\endgroup$
  • $\begingroup$ The centraldiff = (p/(2*changeofx), q/changeofy) is obviously wrong. Then, compare the following three samples and think about what's wrong with the last two: 1. func[x_, y_] := x + y; func @@ {1, 2} 2. (x + y) @@ {1, 2} 3. func[x_, y_] := x + y; func[x, y] @@ {1, 2} $\endgroup$ – xzczd Nov 27 '19 at 5:13
  • 2
    $\begingroup$ You continue to misuse brackets (e.g., definition of centraldiff). Read the documentation. $\endgroup$ – Bob Hanlon Nov 27 '19 at 5:32
  • 1
    $\begingroup$ The previous example applied the points to the equation by just listing "@@@" then the specified point list after the defined equation. Which I assumed I could just reapply to this as it is the same concept but different equation. The equation should be fixed now. I have implemented the use of brackets to define my centraldiff function and tried to follow the example which with you have commented. But I am receiving the error "Assuming suppressed output". $\endgroup$ – subrinarafiq Nov 27 '19 at 6:16
  • 1
    $\begingroup$ No, it's not fixed at all. You're just guessing the syntax wildly based on the code you've obtained. Once again, please make some effort to understand the answers and comments you've obtained so far by reading the document, the link given by @Bob in the comment under your previous question is a starting point. $\endgroup$ – xzczd Nov 27 '19 at 6:27
  • 1
    $\begingroup$ To either Map or Apply a function, the function must be defined with argument(s) either explicitly (e.g., f[x_, y_] := x + y) or implicitly using a pure Function (e.g., f = #1 + #2 &). The previous solutions provided to you defined the mapped/applied functions in one of these manners. $\endgroup$ – Bob Hanlon Nov 27 '19 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.