## Visualize the Basins of Attraction

Which start points lead to which basin? For a steepest descent solver, nearby points generally lead to the same basin; see Basins of Attraction. However, for Optimization Toolbox™ solvers, basins are more complicated.

Plot the `MultiStart` start points from the example, Example of Run with MultiStart, color-coded with the basin where they end.

```% rng(14,'twister') % Uncomment the previous line to get the same output ms = MultiStart; opts = optimoptions(@fmincon,'Algorithm','interior-point'); sixmin = @(x)(4*x(1)^2 - 2.1*x(1)^4 + x(1)^6/3 ... + x(1)*x(2) - 4*x(2)^2 + 4*x(2)^4); problem = createOptimProblem('fmincon','x0',[-1,2],... 'objective',sixmin,'lb',[-3,-3],'ub',[3,3],... 'options',opts); [xminm,fminm,flagm,outptm,manyminsm] = run(ms,problem,50); possColors = 'kbgcrm'; hold on for i = 1:size(manyminsm,2) % Color of this line cIdx = rem(i-1, length(possColors)) + 1; color = possColors(cIdx); % Plot start points u = manyminsm(i).X0; x0ThisMin = reshape([u{:}], 2, length(u)); plot(x0ThisMin(1, :), x0ThisMin(2, :), '.', ... 'Color',color,'MarkerSize',25); % Plot the basin with color i plot(manyminsm(i).X(1), manyminsm(i).X(2), '*', ... 'Color', color, 'MarkerSize',25); end % basin center marked with a *, start points with dots hold off``` The figure shows the centers of the basins by colored `*` symbols. Start points with the same color as the `*` symbol converge to the center of the `*` symbol.

Start points do not always converge to the closest basin. For example, the red points are closer to the cyan basin center than to the red basin center. Also, many black and blue start points are closer to the opposite basin centers.

The magenta and red basins are shallow, as you can see in the following contour plot. ## Support Get trial now
{"ft_lang_label":"__label__en","ft_lang_prob":0.7460614,"math_prob":0.99354726,"size":1757,"snap":"2021-43-2021-49","text_gpt3_token_len":516,"char_repetition_ratio":0.1351968,"word_repetition_ratio":0.007936508,"special_character_ratio":0.31018782,"punctuation_ratio":0.24427481,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9798721,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,2,null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-07T06:52:56Z\",\"WARC-Record-ID\":\"<urn:uuid:54238c0a-fdfd-40c8-a5d5-2d14344da624>\",\"Content-Length\":\"69289\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2d7c83d0-b3d2-46bb-809f-b3da3c686d33>\",\"WARC-Concurrent-To\":\"<urn:uuid:deee8387-1067-4432-a797-94533bdcde1c>\",\"WARC-IP-Address\":\"104.68.243.15\",\"WARC-Target-URI\":\"https://es.mathworks.com/help/gads/visualize-the-basins-of-attraction.html\",\"WARC-Payload-Digest\":\"sha1:RYD3DZY26PHO7RXXKC44EGHDVNNCHWEQ\",\"WARC-Block-Digest\":\"sha1:GAFPRMDKWLVUYTERFIODKMWXG6R7NI64\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363336.93_warc_CC-MAIN-20211207045002-20211207075002-00592.warc.gz\"}"}