Question #95808

Consider the parabola defined by y = x
2 − 2x − 1. The distance d(x) from the origin
(0, 0) to a point (x, y) on the parabola is given by
d(x) = q
x
2 + (x
2 − 2x − 1)
2
.
(a) Write a MATLAB program and function M-file to plot d(x) for −2 ≤ x ≤ 4. Also use the
function M-file and the fminbnd command to find (and display) the point (xmin,ymin) on
the parabola that is closest to the origin and display the minimum distance (i.e., the distance
from the origin to the point (xmin,ymin)).
(b) Write a MATLAB program using the fzero command to find the point(s) on the parabola at
distance 4 from the origin.

Expert's answer

(a) m-file for function d(x):

function y = d(x)
y = sqrt(x.^2 + (x.^2 - 2*x -1).^2);

Matlab program:

fplot(@(x) d(x),[-2 4],'b')


[xmin, dmin] = fminbnd(@d,-2,4)
ymin = xmin^2 - 2*xmin - 1


figure
fplot(@(x) x.^2-2*x-1,[-2,4],'b')
hold on
plot(xmin,ymin,'bo')

Output

xmin =
  -0.3660

dmin =
  0.3898

ymin =
  -0.1340


(b)

>> x1 = fzero(@(x) d(x)-4,-2)
y1 = x1^2 - 2*x1 - 1
x2 = fzero(@(x) d(x)-4,4)
y2 = x2^2 - 2*x2 - 1


x1 =
   -1.3975

y1 =
    3.7479

x2 =
    3.1216

y2 =
    2.5011


So points (-1.3975,3.7479) and (3.1216, 2.5011) are at distance 4 from the origin


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS