Answer to Question #95808 in MatLAB for Ahmed

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.
1
Expert's answer
2019-10-07T08:37:37-0400

(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!

Comments

Assignment Expert
31.03.20, 20:44

Dear Kieran, If you have serious assignment that requires large amount of work and hence cannot be done for free you can submit it as assignment and our experts will surely assist you. Price depends on complexity of your assignments and deadline. Please submit your assignments to our control panel and you'll get price estimation.

Kieran
31.03.20, 09:49

I'm getting different results for part A Output: Columns 1 through 6 4094.52 12994.51 12994.51 10814.51 10402.51 11879.51 Columns 7 through 12 11662.51 9998.51 11879.51 13223.51 2302.52 6398.51 Columns 13 through 15 2599.52 6239.51 2399.52 why is this? Also, how do I use the code in part B to get the answer?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS