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?
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:13centraldiff
). Read the documentation. $\endgroup$ – Bob Hanlon Nov 27 '19 at 5:32Map
orApply
a function, the function must be defined with argument(s) either explicitly (e.g.,f[x_, y_] := x + y
) or implicitly using a pureFunction
(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