Cody

# Problem 43642. Euclidean distance from a point to a polynomial

Solution 2170882

Submitted on 23 Mar 2020
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
x0y0 = [-2 5]; P = [0.5 3 -5]; y_correct = 4.3093988461280149175163000679048; tol = 5e-13; assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

k = 2 k = 3 ans = 4.4721 ans = Columns 1 through 15 20503 20504 20505 20506 20507 20508 20509 20510 20511 20512 20513 20514 20515 20516 20517 Columns 16 through 30 20518 20519 20520 20521 20522 20523 20524 20525 20526 20527 20528 20529 20530 20531 20532 Columns 31 through 45 20533 20534 20535 20536 20537 20538 20539 20540 20541 20542 20543 20544 20545 20546 20547 Columns 46 through 60 20548 20549 20550 20551 20552 20553 20554 20555 20556 20557 20558 20559 20560 20561 20562 Columns 61 through 75 20563 20564 20565 20566 20567 20568 20569 20570 20571 20572 20573 20574 20575 20576 20577 Columns 76 through 90 20578 20579 20580 20581 20582 20583 20584 20585 20586 20587 20588 20589 20590 20591 20592 Columns 91 through 105 20593 20594 20595 20596 20597 20598 20599 20600 20601 20602 20603 20604 20605 20606 20607 Columns 106 through 120 20608 20609 20610 20611 20612 20613 20614 20615 20616 20617 20618 20619 20620 20621 20622 Columns 121 through 135 20623 20624 20625 20626 20627 20628 20629 20630 20631 20632 20633 20634 20635 20636 20637 Columns 136 through 150 20638 20639 20640 20641 20642 20643 20644 20645 20646 20647 20648 20649 20650 20651 20652 Columns 151 through 165 20653 20654 20655 20656 20657 20658 20659 20660 20661 20662 20663 20664 20665 20666 20667 Columns 166 through 180 20668 20669 20670 20671 20672 20673 20674 20675 20676 20677 20678 20679 20680 20681 20682 Columns 181 through 195 20683 20684 20685 20686 20687 20688 20689 20690 20691 20692 20693 20694 20695 20696 20697 Columns 196 through 201 20698 20699 20700 20701 20702 20703

Output argument "D" (and maybe others) not assigned during call to "distance2polynomial". Error in Test1 (line 5) assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

2   Fail
x0y0 = [pi, pi]; P = [10]; y_correct = 6.8584073464102067615373566167205; tol = 7e-13; assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

ans = 6.8599 ans = Columns 1 through 15 20704 20705 20706 20707 20708 20709 20710 20711 20712 20713 20714 20715 20716 20717 20718 Columns 16 through 30 20719 20720 20721 20722 20723 20724 20725 20726 20727 20728 20729 20730 20731 20732 20733 Columns 31 through 45 20734 20735 20736 20737 20738 20739 20740 20741 20742 20743 20744 20745 20746 20747 20748 Columns 46 through 60 20749 20750 20751 20752 20753 20754 20755 20756 20757 20758 20759 20760 20761 20762 20763 Columns 61 through 75 20764 20765 20766 20767 20768 20769 20770 20771 20772 20773 20774 20775 20776 20777 20778 Columns 76 through 90 20779 20780 20781 20782 20783 20784 20785 20786 20787 20788 20789 20790 20791 20792 20793 Columns 91 through 105 20794 20795 20796 20797 20798 20799 20800 20801 20802 20803 20804 20805 20806 20807 20808 Columns 106 through 120 20809 20810 20811 20812 20813 20814 20815 20816 20817 20818 20819 20820 20821 20822 20823 Columns 121 through 135 20824 20825 20826 20827 20828 20829 20830 20831 20832 20833 20834 20835 20836 20837 20838 Columns 136 through 150 20839 20840 20841 20842 20843 20844 20845 20846 20847 20848 20849 20850 20851 20852 20853 Columns 151 through 165 20854 20855 20856 20857 20858 20859 20860 20861 20862 20863 20864 20865 20866 20867 20868 Columns 166 through 180 20869 20870 20871 20872 20873 20874 20875 20876 20877 20878 20879 20880 20881 20882 20883 Columns 181 through 195 20884 20885 20886 20887 20888 20889 20890 20891 20892 20893 20894 20895 20896 20897 20898 Columns 196 through 201 20899 20900 20901 20902 20903 20904

Output argument "D" (and maybe others) not assigned during call to "distance2polynomial". Error in Test2 (line 5) assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

3   Fail
x0y0 = [0.25,50]; P = [1 2 3 4 5]; y_correct = 1.6470039192886012020234097061626; tol = 5e-13; assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

k = 2 k = 3 k = 4 k = 5 ans = 4.4230 ans = Columns 1 through 15 19498 19499 19500 19501 19502 19503 19504 19505 19506 19507 19508 19509 19510 19511 19512 Columns 16 through 30 19513 19514 19515 19516 19517 19518 19519 19520 19521 19522 19523 19524 19525 19526 19527 Columns 31 through 45 19528 19529 19530 19531 19532 19533 19534 19535 19536 19537 19538 19539 19540 19541 19542 Columns 46 through 60 19543 19544 19545 19546 19547 19548 19549 19550 19551 19552 19553 19554 19555 19556 19557 Columns 61 through 75 19558 19559 19560 19561 19562 19563 19564 19565 19566 19567 19568 19569 19570 19571 19572 Columns 76 through 90 19573 19574 19575 19576 19577 19578 19579 19580 19581 19582 19583 19584 19585 19586 19587 Columns 91 through 105 19588 19589 19590 19591 19592 19593 19594 19595 19596 19597 19598 19599 19600 19601 19602 Columns 106 through 120 19603 19604 19605 19606 19607 19608 19609 19610 19611 19612 19613 19614 19615 19616 19617 Columns 121 through 135 19618 19619 19620 19621 19622 19623 19624 19625 19626 19627 19628 19629 19630 19631 19632 Columns 136 through 150 19633 19634 19635 19636 19637 19638 19639 19640 19641 19642 19643 19644 19645 19646 19647 Columns 151 through 165 19648 19649 19650 19651 19652 19653 19654 19655 19656 19657 19658 19659 19660 19661 19662 Columns 166 through 180 19663 19664 19665 19666 19667 19668 19669 19670 19671 19672 19673 19674 19675 19676 19677 Columns 181 through 195 19678 19679 19680 19681 19682 19683 19684 19685 19686 19687 19688 19689 19690 19691 19692 Columns 196 through 201 19693 19694 19695 19696 19697 19698

Output argument "D" (and maybe others) not assigned during call to "distance2polynomial". Error in Test3 (line 5) assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

4   Fail
x0y0 = [-3 -3]; P = [-2 1]; y_correct = 4.4721359549995793928183473374626; tol = 5e-13; assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

k = 2 ans = 4.4721 ans = Columns 1 through 15 20302 20303 20304 20305 20306 20307 20308 20309 20310 20311 20312 20313 20314 20315 20316 Columns 16 through 30 20317 20318 20319 20320 20321 20322 20323 20324 20325 20326 20327 20328 20329 20330 20331 Columns 31 through 45 20332 20333 20334 20335 20336 20337 20338 20339 20340 20341 20342 20343 20344 20345 20346 Columns 46 through 60 20347 20348 20349 20350 20351 20352 20353 20354 20355 20356 20357 20358 20359 20360 20361 Columns 61 through 75 20362 20363 20364 20365 20366 20367 20368 20369 20370 20371 20372 20373 20374 20375 20376 Columns 76 through 90 20377 20378 20379 20380 20381 20382 20383 20384 20385 20386 20387 20388 20389 20390 20391 Columns 91 through 105 20392 20393 20394 20395 20396 20397 20398 20399 20400 20401 20402 20403 20404 20405 20406 Columns 106 through 120 20407 20408 20409 20410 20411 20412 20413 20414 20415 20416 20417 20418 20419 20420 20421 Columns 121 through 135 20422 20423 20424 20425 20426 20427 20428 20429 20430 20431 20432 20433 20434 20435 20436 Columns 136 through 150 20437 20438 20439 20440 20441 20442 20443 20444 20445 20446 20447 20448 20449 20450 20451 Columns 151 through 165 20452 20453 20454 20455 20456 20457 20458 20459 20460 20461 20462 20463 20464 20465 20466 Columns 166 through 180 20467 20468 20469 20470 20471 20472 20473 20474 20475 20476 20477 20478 20479 20480 20481 Columns 181 through 195 20482 20483 20484 20485 20486 20487 20488 20489 20490 20491 20492 20493 20494 20495 20496 Columns 196 through 201 20497 20498 20499 20500 20501 20502

Output argument "D" (and maybe others) not assigned during call to "distance2polynomial". Error in Test4 (line 5) assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

5   Fail
x0y0 = [0 5]; P = [1 0 1]; y_correct = 1.9364916731037084425896326998912; tol = 2e-13; assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

k = 2 k = 3 ans = 2 ans = Columns 1 through 15 19699 19700 19701 19702 19703 19704 19705 19706 19707 19708 19709 19710 19711 19712 19713 Columns 16 through 30 19714 19715 19716 19717 19718 19719 19720 19721 19722 19723 19724 19725 19726 19727 19728 Columns 31 through 45 19729 19730 19731 19732 19733 19734 19735 19736 19737 19738 19739 19740 19741 19742 19743 Columns 46 through 60 19744 19745 19746 19747 19748 19749 19750 19751 19752 19753 19754 19755 19756 19757 19758 Columns 61 through 75 19759 19760 19761 19762 19763 19764 19765 19766 19767 19768 19769 19770 19771 19772 19773 Columns 76 through 90 19774 19775 19776 19777 19778 19779 19780 19781 19782 19783 19784 19785 19786 19787 19788 Columns 91 through 105 19789 19790 19791 19792 19793 19794 19795 19796 19797 19798 19799 19800 19801 19802 19803 Columns 106 through 120 19804 19805 19806 19807 19808 19809 19810 19811 19812 19813 19814 19815 19816 19817 19818 Columns 121 through 135 19819 19820 19821 19822 19823 19824 19825 19826 19827 19828 19829 19830 19831 19832 19833 Columns 136 through 150 19834 19835 19836 19837 19838 19839 19840 19841 19842 19843 19844 19845 19846 19847 19848 Columns 151 through 165 19849 19850 19851 19852 19853 19854 19855 19856 19857 19858 19859 19860 19861 19862 19863 Columns 166 through 180 19864 19865 19866 19867 19868 19869 19870 19871 19872 19873 19874 19875 19876 19877 19878 Columns 181 through 195 19879 19880 19881 19882 19883 19884 19885 19886 19887 19888 19889 19890 19891 19892 19893 Columns 196 through 210 19894 19895 19896 19897 19898 19899 20503 20504 20505 20506 20507 20508 20509 20510 20511 Columns 211 through 225 20512 20513 20514 20515 20516 20517 20518 20519 20520 20521 20522 20523 20524 20525 20526 Columns 226 through 240 20527 20528 20529 20530 20531 20532 20533 20534 20535 20536 20537 20538 20539 20540 20541 Columns 241 through 255 20542 20543 20544 20545 20546 20547 20548 20549 20550 20551 20552 20553 20554 20555 20556 Columns 256 through 270 20557 20558 20559 20560 20561 20562 20563 20564 20565 20566 20567 20568 20569 20570 20571 Columns 271 through 285 20572 20573 20574 20575 20576 20577 20578 20579 20580 20581 20582 20583 20584 20585 20586 Columns 286 through 300 20587 20588 20589 20590 20591 20592 20593 20594 20595 20596 20597 20598 20599 20600 20601 Columns 301 through 315 20602 20603 20604 20605 20606 20607 20608 20609 20610 20611 20612 20613 20614 20615 20616 Columns 316 through 330 20617 20618 20619 20620 20621 20622 20623 20624 20625 20626 20627 20628 20629 20630 20631 Columns 331 through 345 20632 20633 20634 20635 20636 20637 20638 20639 20640 20641 20642 20643 20644 20645 20646 Columns 346 through 360 20647 20648 20649 20650 20651 20652 20653 20654 20655 20656 20657 20658 20659 20660 20661 Columns 361 through 375 20662 20663 20664 20665 20666 20667 20668 20669 20670 20671 20672 20673 20674 20675 20676 Columns 376 through 390 20677 20678 20679 20680 20681 20682 20683 20684 20685 20686 20687 20688 20689 20690 20691 Columns 391 through 402 20692 20693 20694 20695 20696 20697 20698 20699 20700 20701 20702 20703

Output argument "D" (and maybe others) not assigned during call to "distance2polynomial". Error in Test5 (line 5) assert(abs(distance2polynomial(P,x0y0)-y_correct) < tol)

6   Fail
x0y0 = [-2 -5]; P = [0.5 3 -5]; y_correct = 1.8901381949770695260066523338279; tol = 2e-13; (abs(distance2polynomial(P,x0y0)-y_correct) < tol)

k = 2 k = 3 ans = 2 ans = Columns 1 through 15 20101 20102 20103 20104 20105 20106 20107 20108 20109 20110 20111 20112 20113 20114 20115 Columns 16 through 30 20116 20117 20118 20119 20120 20121 20122 20123 20124 20125 20126 20127 20128 20129 20130 Columns 31 through 45 20131 20132 20133 20134 20135 20136 20137 20138 20139 20140 20141 20142 20143 20144 20145 Columns 46 through 60 20146 20147 20148 20149 20150 20151 20152 20153 20154 20155 20156 20157 20158 20159 20160 Columns 61 through 75 20161 20162 20163 20164 20165 20166 20167 20168 20169 20170 20171 20172 20173 20174 20175 Columns 76 through 90 20176 20177 20178 20179 20180 20181 20182 20183 20184 20185 20186 20187 20188 20189 20190 Columns 91 through 105 20191 20192 20193 20194 20195 20196 20197 20198 20199 20200 20201 20202 20203 20204 20205 Columns 106 through 120 20206 20207 20208 20209 20210 20211 20212 20213 20214 20215 20216 20217 20218 20219 20220 Columns 121 through 135 20221 20222 20223 20224 20225 20226 20227 20228 20229 20230 20231 20232 20233 20234 20235 Columns 136 through 150 20236 20237 20238 20239 20240 20241 20242 20243 20244 20245 20246 20247 20248 20249 20250 Columns 151 through 165 20251 20252 20253 20254 20255 20256 20257 20258 20259 20260 20261 20262 20263 20264 20265 Columns 166 through 180 20266 20267 20268 20269 20270 20271 20272 20273 20274 20275 20276 20277 20278 20279 20280 Columns 181 through 195 20281 20282 20283 20284 20285 20286 20287 20288 20289 20290 20291 20292 20293 20294 20295 Columns 196 through 201 20296 20297 20298 20299 20300 20301

Output argument "D" (and maybe others) not assigned during call to "distance2polynomial". Error in Test6 (line 5) (abs(distance2polynomial(P,x0y0)-y_correct) < tol)