Cody

# Problem 493. Quasi-Newton Method for Unconstrained Minimization using BFGS Update

Solution 1988765

Submitted on 24 Oct 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
% Rosenbrock's banana function F=@(x) 100*(x(2)-x(1).^2).^2 + (1-x(1)).^2; gradF=@(x) [100*(4*x(1).^3-4*x(1).*x(2))+2*x(1)-2; 100*(2*x(2)-2*x(1).^2)]; x0 = [-1.9; 2.0]; x1=[ -1.4478 2.1184]; x2=[ 1.7064 2.9446]; f1=6.0419; f2=0.6068; [xmin,fmin]=BFGS_Quasi_Newton(F,gradF,x0,0.01,1) % single steepest descent assert(norm(xmin-x1)<0.2||norm(xmin-x2)<0.2) assert( abs(fmin-f1)<0.5|| abs(fmin-f2)<0.5) % 2 local min

x= -1.9000 2.0000 iter:=1 alpha 1 value 195.1617 xmin = -0.9326 2.2534 fmin = 195.1617

Assertion failed.

2   Fail
% Rosenbrock's banana function F=@(x) 100*(x(2)-x(1).^2).^2 + (1-x(1)).^2; gradF=@(x) [100*(4*x(1).^3-4*x(1).*x(2))+2*x(1)-2; 100*(2*x(2)-2*x(1).^2)]; x0 = [0; 0]; xcorrect=[ 0.2927 0.0506]; fcorrect=0.63; [xmin,fmin]=BFGS_Quasi_Newton(F,gradF,x0,1e-2,2) % two iterations assert(norm(xmin-xcorrect)<0.1) assert( abs(fmin-fcorrect)<0.01)

x= 0 0 iter:=1 alpha 0.2500 value 0.9531 x= 0.2500 0 iter:=2 alpha 0.0625 value 0.5823 xmin = 0.2383 0.0614 fmin = 0.5823

Assertion failed.

3   Fail
% Rosenbrock's banana function F=@(x) 100*(x(2)-x(1).^2).^2 + (1-x(1)).^2; gradF=@(x) [100*(4*x(1).^3-4*x(1).*x(2))+2*x(1)-2; 100*(2*x(2)-2*x(1).^2)]; x0 = [0;0]; xcorrect = [1;1;]; fcorrect = 0; [xmin,fmin]=BFGS_Quasi_Newton(F,gradF,x0) assert(norm(xmin-xcorrect)<0.01) assert(abs(fmin-fcorrect)<0.01);

x= 0 0 iter:=1 alpha 0.2500 value 0.9531 x= 0.2500 0 iter:=2 alpha 0.0625 value 0.5823 x= 0.2383 0.0614 iter:=3 alpha 0.0625 value 0.5326 x= 0.3003 0.0694 iter:=4 alpha 0.0312 value 0.5177 x= 0.2937 0.1000 iter:=5 alpha 0.0625 value 0.5031 x= 0.3561 0.0971 iter:=6 alpha 0.0312 value 0.4259 x= 0.3496 0.1276 iter:=7 alpha 0.0312 value 0.4042 x= 0.3808 0.1306 iter:=8 alpha 0.0156 value 0.3882 x= 0.3778 0.1459 iter:=9 alpha 0.0312 value 0.3861 x= 0.4090 0.1481 iter:=10 alpha 0.0156 value 0.3538 x= 0.4053 0.1633 iter:=11 alpha 0.0156 value 0.3458 x= 0.4205 0.1668 iter:=12 alpha 0.0078 value 0.3380 x= 0.4186 0.1744 iter:=13 alpha 0.0156 value 0.3310 x= 0.4339 0.1780 iter:=14 alpha 0.0078 value 0.3228 x= 0.4319 0.1855 iter:=15 alpha 0.0156 value 0.3168 x= 0.4471 0.1893 iter:=16 alpha 0.0078 value 0.3082 x= 0.4450 0.1969 iter:=17 alpha 0.0156 value 0.3028 x= 0.4600 0.2010 iter:=18 alpha 0.0078 value 0.2941 x= 0.4578 0.2085 iter:=19 alpha 0.0156 value 0.2891 x= 0.4728 0.2130 iter:=20 alpha 0.0078 value 0.2806 x= 0.4703 0.2204 iter:=21 alpha 0.0156 value 0.2757 x= 0.4853 0.2251 iter:=22 alpha 0.0078 value 0.2676 x= 0.4827 0.2325 iter:=23 alpha 0.0156 value 0.2630 x= 0.4976 0.2373 iter:=24 alpha 0.0078 value 0.2550 x= 0.4950 0.2447 iter:=25 alpha 0.0156 value 0.2508 x= 0.5098 0.2496 iter:=26 alpha 0.0078 value 0.2429 x= 0.5072 0.2570 iter:=27 alpha 0.0156 value 0.2392 x= 0.5219 0.2621 iter:=28 alpha 0.0078 value 0.2312 x= 0.5192 0.2694 iter:=29 alpha 0.0156 value 0.2281 x= 0.5339 0.2746 iter:=30 alpha 0.0078 value 0.2199 x= 0.5311 0.2819 iter:=31 alpha 0.0156 value 0.2174 x= 0.5457 0.2873 iter:=32 alpha 0.0078 value 0.2090 x= 0.5428 0.2946 iter:=33 alpha 0.0156 value 0.2069 x= 0.5574 0.3002 iter:=34 alpha 0.0078 value 0.1986 x= 0.5544 0.3074 iter:=35 alpha 0.0156 value 0.1967 x= 0.5689 0.3132 iter:=36 alpha 0.0078 value 0.1886 x= 0.5658 0.3204 iter:=37 alpha 0.0156 value 0.1869 x= 0.5802 0.3263 iter:=38 alpha 0.0078 value 0.1789 x= 0.5770 0.3335 iter:=39 alpha 0.0156 value 0.1774 x= 0.5914 0.3395 iter:=40 alpha 0.0078 value 0.1697 x= 0.5881 0.3466 iter:=41 alpha 0.0156 value 0.1684 x= 0.6025 0.3528 iter:=42 alpha 0.0078 value 0.1608 x= 0.5992 0.3599 iter:=43 alpha 0.0156 value 0.1598 x= 0.6135 0.3662 iter:=44 alpha 0.0078 value 0.1521 x= 0.6101 0.3732 iter:=45 alpha 0.0156 value 0.1516 x= 0.6244 0.3796 iter:=46 alpha 0.0078 value 0.1438 x= 0.6209 0.3866 iter:=47 alpha 0.0156 value 0.1437 x= 0.6351 0.3931 iter:=48 alpha 0.0078 value 0.1358 x= 0.6316 0.4001 iter:=49 alpha 0.0078 value 0.1326 x= 0.6387 0.4034 iter:=50 alpha 0.0039 value 0.1319 x= 0.6370 0.4069 iter:=51 alpha 0.0078 value 0.1293 x= 0.6443 0.4099 iter:=52 alpha 0.0039 value 0.1276 x= 0.6427 0.4135 iter:=53 alpha 0.0078 value 0.1263 x= 0.6500 0.4163 iter:=54 alpha 0.0039 value 0.1236 x= 0.6485 0.4199 iter:=55 alpha 0.0078 value 0.1235 x= 0.6557 0.4229 iter:=56 alpha 0.0078 value 0.1226 x= 0.6525 0.4300 iter:=57 alpha 0.0156 value 0.1194 x= 0.6671 0.4357 iter:=58 alpha 0.0078 value 0.1133 x= 0.6640 0.4429 iter:=59 alpha 0.0078 value 0.1104 x= 0.6713 0.4457 iter:=60 alpha 0.0039 value 0.1091 x= 0.6698 0.4494 iter:=61 alpha 0.0078 value 0.1084 x= 0.6771 0.4521 iter:=62 alpha 0.0039 value 0.1053 x= 0.6757 0.4557 iter:=63 alpha 0.0039 value 0.1047 x= 0.6793 0.4572 iter:=64 alpha 0.0039 value 0.1041 x= 0.6777 0.4608 iter:=65 alpha 0.0078 value 0.1025 x= 0.6851 0.4635 iter:=66 alpha 0.0039 value 0.1001 x= 0.6836 0.4672 iter:=67 alpha 0.0039 value 0.0992 x= 0.6872 0.4686 iter:=68 alpha 0.0039 value 0.0991 x= 0.6858 0.4722 iter:=69 alpha 0.0078 value 0.0974 x= 0.6931 0.4748 iter:=70 alpha 0.0039 value 0.0950 x= 0.6918 0.4784 iter:=71 alpha 0.0039 value 0.0942 x= 0.6954 0.4798 iter:=72 alpha 0.0039 value 0.0939 x= 0.6941 0.4834 iter:=73 alpha 0.0078 value 0.0929 x= 0.7015 0.4859 iter:=74 alpha 0.0039 value 0.0900 x= 0.7001 0.4896 iter:=75 alpha 0.0039 value 0.0897 x= 0.7038 0.4909 iter:=76 alpha 0.0039 value 0.0887 x= 0.7024 0.4946 iter:=77 alpha 0.0078 value 0.0885 x= 0.7097 0.4972 iter:=78 alpha 0.0078 value 0.0882 x= 0.7069 0.5045 iter:=79 alpha 0.0078 value 0.0827 x= 0.7143 0.5070 iter:=80 alpha 0.0020 value 0.0820 x= 0.7137 0.5089 iter:=81 alpha 0.0039 value 0.0819 x= 0.7173 0.5101 iter:=82 alpha 0.0039 value 0.0808 x= 0.7160 0.5138 iter:=83 alpha 0.0039 value 0.0794 x= 0.7197 0.5150 iter:=84 alpha 0.0020 value 0.0789 x= 0.7190 0.5169 iter:=85 alpha 0.0039 value 0.0787 x= 0.7228 0.5181 iter:=86 alpha 0.0039 value 0.0778 x= 0.7214 0.5218 iter:=87 alpha 0.0039 value 0.0763 x= 0.7251 0.5230 iter:=88 alpha 0.0020 value 0.0759 x= 0.7245 0.5249 iter:=89 alpha 0.0039 value 0.0757 x= 0.7282 0.5261 iter:=90 alpha 0.0039 value 0.0747 x= 0.7270 0.5298 iter:=91 alpha 0.0039 value 0.0734 x= 0.7307 0.5310 iter:=92 alpha 0.0020 value 0.0729 x= 0.7301 0.5328 iter:=93 alpha 0.0020 value 0.0724 x= 0.7319 0.5334 iter:=94 alpha 0.0020 value 0.0722 x= 0.7314 0.5353 iter:=95 alpha 0.0039 value 0.0718 x= 0.7351 0.5364 iter:=96 alpha 0.0039 value 0.0710 x= 0.7339 0.5401 iter:=97 alpha 0.0039 value 0.0697 x= 0.7377 0.5412 iter:=98 alpha 0.0020 value 0.0691 x= 0.7371 0.5431 iter:=99 alpha 0.0020 value 0.0687 x= 0.7390 0.5436 iter:=100 alpha 0.0020 value 0.0684 xmin = 0.7384 0.5455 fmin = 0.0684

Assertion failed.

4   Pass
% Rosenbrock's banana function F=@(x) 100*(x(2)-x(1).^2).^2 + (1-x(1)).^2; gradF=@(x) [100*(4*x(1).^3-4*x(1).*x(2))+2*x(1)-2; 100*(2*x(2)-2*x(1).^2)]; HessF=@(x) 200*[4*x(1).^2-2*(x(2)-x(1).^2)+1/100, -2*x(1); -2*x(1), 1]; xcorrect = [1;1]; fcorrect = 0; x0 = [-1.9; 2]; [xmin,fmin]=BFGS_Quasi_Newton(F,gradF,x0,1e-4) assert(isequal(round(xmin),xcorrect)) assert(isequal(round(fmin),fcorrect))

x= -1.9000 2.0000 iter:=1 alpha 1 value 195.1617 x= -0.9326 2.2534 iter:=2 alpha 1 value 69.9948 x= -0.6824 1.2852 iter:=3 alpha 1.0000e-04 value 70.0202 x= -0.6823 1.2852 iter:=4 alpha 0.5000 value 6.9053 x= -1.1809 1.2479 iter:=5 alpha 1.0000e-04 value 6.9077 x= -1.1809 1.2478 iter:=6 alpha 0.2500 value 5.2812 x= -1.1956 1.4974 iter:=7 alpha 1.0000e-04 value 5.2841 x= -1.1955 1.4974 iter:=8 alpha 0.0312 value 4.9690 x= -1.2266 1.4938 iter:=9 alpha 1.0000e-04 value 4.9691 x= -1.2266 1.4937 iter:=10 alpha 0.0156 value 4.9690 x= -1.2193 1.5076 iter:=11 alpha 1.0000e-04 value 4.9693 x= -1.2192 1.5075 iter:=12 alpha 0.0078 value 4.9485 x= -1.2244 1.5017 iter:=13 alpha 0.0156 value 4.9388 x= -1.2127 1.4913 iter:=14 alpha 0.0078 value 4.9195 x= -1.2179 1.4855 iter:=15 alpha 0.0156 value 4.9081 x= -1.2062 1.4751 iter:=16 alpha 0.0078 value 4.8905 x= -1.2114 1.4693 iter:=17 alpha 0.0156 value 4.8773 x= -1.1997 1.4589 iter:=18 alpha 0.0078 value 4.8616 x= -1.2049 1.4531 iter:=19 alpha 0.0156 value 4.8463 x= -1.1932 1.4427 iter:=20 alpha 0.0078 value 4.8328 x= -1.1983 1.4369 iter:=21 alpha 0.0156 value 4.8152 x= -1.1866 1.4265 iter:=22 alpha 0.0078 value 4.8041 x= -1.1918 1.4207 iter:=23 alpha 0.0156 value 4.7842 x= -1.1801 1.4103 iter:=24 alpha 0.0078 value 4.7754 x= -1.1853 1.4045 iter:=25 alpha 0.0156 value 4.7531 x= -1.1735 1.3942 iter:=26 alpha 0.0078 value 4.7468 x= -1.1787 1.3883 iter:=27 alpha 0.0156 value 4.7220 x= -1.1669 1.3780 iter:=28 alpha 0.0078 value 4.7182 x= -1.1721 1.3721 iter:=29 alpha 0.0156 value 4.6910 x= -1.1603 1.3618 iter:=30 alpha 0.0078 value 4.6897 x= -1.1654 1.3560 iter:=31 alpha 0.0312 value 4.6876 x= -1.1419 1.3355 iter:=32 alpha 0.0156 value 4.6329 x= -1.1521 1.3237 iter:=33 alpha 0.0312 value 4.6184 x= -1.1285 1.3032 iter:=34 alpha 0.0156 value 4.5773 x= -1.1388 1.2914 iter:=35 alpha 0.0312 value 4.5487 x= -1.1152 1.2709 iter:=36 alpha 0.0156 value 4.5228 x= -1.1254 1.2591 iter:=37 alpha 0.0312 value 4.4788 x= -1.1018 1.2387 iter:=38 alpha 0.0156 value 4.4700 x= -1.1120 1.2269 iter:=39 alpha 0.0312 value 4.4094 x= -1.0883 1.2065 iter:=40 alpha 0.0078 value 4.3849 x= -1.0934 1.2005 iter:=41 alpha 0.0156 value 4.3749 x= -1.0816 1.1903 iter:=42 alpha 0.0078 value 4.3556 x= -1.0867 1.1844 iter:=43 alpha 0.0156 value 4.3406 x= -1.0749 1.1742 iter:=44 alpha 0.0078 value 4.3268 x= -1.0800 1.1683 iter:=45 alpha 0.0156 value 4.3067 x= -1.0682 1.1581 iter:=46 alpha 0.0078 value 4.2984 x= -1.0733 1.1522 iter:=47 alpha 0.0312 value 4.2924 x= -1.0495 1.1318 iter:=48 alpha 0.0156 value 4.2434 x= -1.0597 1.1200 iter:=49 alpha 0.0312 value 4.2146 x= -1.0360 1.0996 iter:=50 alpha 0.0156 value 4.1914 x= -1.0462 1.0878 iter:=51 alpha 0.0312 value 4.1390 x= -1.0225 1.0675 iter:=52 alpha 0.0078 value 4.1142 x= -1.0275 1.0615 iter:=53 alpha 0.0156 value 4.1021 x= -1.0157 1.0514 iter:=54 alpha 0.0078 value 4.0847 x= -1.0208 1.0454 iter:=55 alpha 0.0156 value 4.0660 x= -1.0089 1.0353 iter:=56 alpha 0.0078 value 4.0562 x= -1.0140 1.0293 iter:=57 alpha 0.0312 value 4.0426 x= -0.9902 1.0091 iter:=58 alpha 0.0156 value 4.0026 x= -1.0003 0.9972 iter:=59 alpha 0.0312 value 3.9609 x= -0.9766 0.9769 iter:=60 alpha 0.0156 value 3.9542 x= -0.9867 0.9650 iter:=61 alpha 0.0625 value 3.9424 x= -0.9391 0.9246 iter:=62 alpha 0.0312 value 3.8770 x= -0.9593 0.9008 iter:=63 alpha 0.0625 value 3.7398 x= -0.9116 0.8603 iter:=64 alpha 0.0156 value 3.6933 x= -0.9218 0.8484 iter:=65 alpha 0.0312 value 3.6504 x= -0.8979 0.8282 iter:=66 alpha 0.0156 value 3.6472 x= -0.9080 0.8163 iter:=67 alpha 1 value 3.5797 x= -0.1438 0.1714 iter:=68 alpha 0.2500 value 0.9140 x= 0.0469 0.0097 iter:=69 alpha 1.0000e-04 value 0.9140 x= 0.0468 0.0096 iter:=70 alpha 1.0000e-04 value 0.9143 x= 0.0467 0.0096 iter:=71 alpha 0.0078 value 0.9121 x= 0.0450 0.0020 iter:=72 alpha 1.0000e-04 value 0.9123 x= 0.0449 0.0021 iter:=73 alpha 0.0156 value 0.9063 x= 0.0558 -0.0091 iter:=74 alpha 0.0625 value 0.8710 x= 0.1003 0.0349 iter:=75 alpha 0.0625 value 0.8249 x= 0.1442 -0.0096 iter:=76 alpha 1 value 0.1567 x= 0.8548 0.6939 iter:=77 alpha 1.0000e-04 value 0.1581 x= 0.8549 0.6939 iter:=78 alpha 0.0312 value 0.0814 x= 0.8317 0.7148 iter:=79 alpha 1.0000e-04 value 0.0815 x= 0.8317 0.7147 iter:=80 alpha 0.0625 value 0.0376 x= 0.8783 0.7563 iter:=81 alpha 0.0078 value 0.0161 x= 0.8731 0.7621 iter:=82 alpha 0.0039 value 0.0161 x= 0.8760 0.7647 iter:=83 alpha 0.0020 value 0.0158 x= 0.8747 0.7662 iter:=84 alpha 0.0039 value 0.0152 x= 0.8776 0.7688 iter:=85 alpha 9.7656e-04 value 0.0152 x= 0.8770 0.7695 iter:=86 alpha 0.0039 value 0.0149 x= 0.8799 0.7721 iter:=87 alpha 9.7656e-04 value 0.0146 x= 0.8792 0.7729 iter:=88 alpha 0.0020 value 0.0145 x= 0.8807 0.7742 iter:=89 alpha 9.7656e-04 value 0.0144 x= 0.8801 0.7749 iter:=90 alpha 0.0039 value 0.0142 x= 0.8830 0.7775 iter:=91 alpha 9.7656e-04 value 0.0139 x= 0.8823 0.7782 iter:=92 alpha 0.0020 value 0.0138 x= 0.8838 0.7795 iter:=93 alpha 9.7656e-04 value 0.0137 x= 0.8832 0.7802 iter:=94 alpha 0.0039 value 0.0135 x= 0.8861 0.7828 iter:=95 alpha 0.0020 value 0.0135 x= 0.8848 0.7843 iter:=96 alpha 0.0078 value 0.0134 x= 0.8907 0.7894 iter:=97 alpha 0.0020 value 0.0122 x= 0.8894 0.7909 iter:=98 alpha 0.0020 value 0.0121 x= 0.8908 0.7922 iter:=99 alpha 9.7656e-04 value 0.0121 x= 0.8902 0.7929 iter:=100 alpha 0.0039 value 0.0119 xmin = 0.8931 0.7955 fmin = 0.0119