Cody

Problem 43642. Euclidean distance from a point to a polynomial

Solution 4474132

Submitted on 27 Dec 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)

Error using dsearchn (line 63) X and XI should have the same column dimension. Error in distance2polynomial (line 2) D=dsearchn(P,q) 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)

Error using dsearchn (line 63) X and XI should have the same column dimension. Error in distance2polynomial (line 2) D=dsearchn(P,q) 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)

Error using dsearchn (line 63) X and XI should have the same column dimension. Error in distance2polynomial (line 2) D=dsearchn(P,q) 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)

D = 1

Assertion failed.

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

Error using dsearchn (line 63) X and XI should have the same column dimension. Error in distance2polynomial (line 2) D=dsearchn(P,q) 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)

Error using dsearchn (line 63) X and XI should have the same column dimension. Error in distance2polynomial (line 2) D=dsearchn(P,q) Error in Test6 (line 5) (abs(distance2polynomial(P,x0y0)-y_correct) < tol)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!