optimization - MATLAB script gives me NaN even for setting variables to integers -
After running this script everything is set to NaN and nothing happens. I'm just trying to do a second method on a 2-D function where a variable is set to 0.
hi = @ (x, y) exp (-3 * ((x + 0.5). ^ 2 + 2 * y ^ 2)) + exp (-x ^ 2 - 2 * y ^ 2). * Cos (4 * x) - 1e-3; Tol = 1e-10; Yi = 0; X0 = -2; X1 = 2; F0 = hi (x0, yi); F1 = hi (x1, yi); For Jj = 1:24 x2 = x1 - f1 * (x1-x0) / (F1-F0); F2 = hi (x2, yi); If (stomach (x2-x1) & lt; tol) root = x2; Break x0 = x1; X1 = x2; F0 = F1; F1 = F2; End of End
Here are two problems: I have been in the first line:
x2 = x1 - f1 * (x1-x0) / (f1-f0); The function decreases when x2 with f1-f0 with every code will cause the forum to blow it up Can abs (f1-f0) & lt; By adding tol with x2 = x1 - f1 * (x1-x0) / (f1-f0 + tol) or tol ; However, this will not find the route you want. Your function reveals the graphing problem:
You start the search on x0 = -2 and x1 = + 2 , which are two values that force three roots, but search x2 = -10.5203 , and will continue to try and search for root located on infinity. If you choose the best values, you can use the original code to find all the three basic values. For example: x0 x1 root ------ ------ ------ -1.0 +1.0 1.9522 -0.5 +0.5 0.4164 +0.6 +1.0 1.178 9 When searching (or decreasing / maximizing) roots, the starting point of search often makes a difference. It is best to double check your starting points and learn more about the work you are working with.
Comments
Post a Comment