(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
Comments
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.
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