0
$\begingroup$

I have a problem with this code. I need to find a zero of a function with Davidon–Fletcher–Powell method, which is known as Quasi Newton's method for finding a zero of a function.This is the given function f(x,y,z)=(Cos[xy] - z, Sin[xz] - y, x - 2*y*z) and I need to find a zero of this function with an accuracy of 8 decimals.

f[{x_, y_, z_}] = {Cos[x*y] - z, Sin[x*z] - y, x - 2*y*z};
df[{x_, y_, z_}] = {D[f[{x, y, z}], x], D[f[{x, y, z}], y], 
D[f[{x, y, z}], z]};
 x = {0, 0, 0};
  k = 0;
    eps = 0.0001;
B = IdentityMatrix[3];
Print["x0=", N[x]];
 While[Norm[df[x]] >= eps, p = -Inverse[B].df[x];
 fi[alfa_] = f[x + alfa*p];
 a = alfa /. Minimize[fi[alfa], {alfa}][[2]][[1]];
 xnovo = x + a*p;
 s = xnovo - x;
  y = df[xnovo] - df[x];
 B = B - (Outer[Times, B.s, s.B])/(s.B.s) + (Outer[Times, y, y])/(s.y);
 k = k + 1;
 x = xnovo;
 Print["x", k, "=", N[x]]]
$\endgroup$
  • $\begingroup$ What is not understandable in the error message Minimize::objfs: The objective function {1-alfa,1,1} should be scalar-valued.? You are using line search for a scalar function but the function is vector-valued function, because you try to find the zeroes of a vector-valued function. $\endgroup$ – Henrik Schumacher Mar 26 at 13:14
  • $\begingroup$ I do not know how to change that. $\endgroup$ – User1234 Mar 26 at 13:23
  • $\begingroup$ Really, I have to think about what you want to do. DFP for equation solving $f = 0$ should work without any derivative of $f$. $\endgroup$ – Henrik Schumacher Mar 26 at 13:40
  • $\begingroup$ See also this: en.wikipedia.org/wiki/Broyden%27s_method $\endgroup$ – Henrik Schumacher Mar 26 at 13:44
  • 1
    $\begingroup$ Honestly, I'm quite uncomfortable with the use of Minimize[] for line searching. Using FindMinimum[] instead is still awkward, but much less so. $\endgroup$ – J. M.'s technical difficulties Mar 26 at 14:36

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.