Professional Documents
Culture Documents
Assignment 8 Solution
Problem 1
Before we use bisection method to solve the problem, we can check the number of solutions and
the intervals from looking at the graph. The graph shows that two solutions exist on the interval
[1, 2] and [5, 6].
4
2
0
0
-2
-4
-6
-8
-10
-12
-14
-16
result =
1.70000
By changing xl to 5 and xr to 6, we get
result =
5.40687
Problem 2
Since it is a unimodal function on [0,10], we can use golden search method.
0.3
0.25
0.2
0.15
0.1
0.05
0
0.4
0.8
1.2
1.6
2
2.4
2.8
3.2
3.6
4
4.4
4.8
5.2
5.6
6
6.4
6.8
7.2
7.6
8
8.4
8.8
9.2
9.6
10
golden
ans =
1.2785
Question 3
-Backtracking search method:
Matlab code (Function File)
function y = f(x)
y = exp(1-x(1)-x(2))+ exp(x(1)+x(2)-1)+x(1)^2+x(1)*x(2)+x(2)^2+2*x(1)-3*x(2);
gradient_descent
ans =
-2.1418
2.8582
% if the
x = xtemp;
end
gradient_exact
ans =
-2.1418
2.8582
Problem 4
Matlab Code (Main)
x = [0; 0];
epsilon = 0.00001;
iter = 0;
while norm(gradient(x)) > epsilon
xtemp = x - inv(hessian(x)) * gradient(x);
plot(x(1), x(2), '*r');
hold on;
plot([x(1), xtemp(1)], [x(2), xtemp(2)], '-g');
hold on;
iter = iter + 1;
x = xtemp;
end
newton
ans =
-2.1418
2.8582