This is the error bound , see "Errors for linear systems".
Problem 4
t = [0; 1; 3];
y = [2; 4; 3]
y = 3×1
2
4
3
A = [t, t.^2]
A = 3×2
0 0
1 1
3 9
M = A'*A
M = 2×2
10 28
28 82
v = A'*y
v = 2×1
13
31
c = M\v % solve normal equations A*c = v
c = 2×1
5.5000
-1.5000
Instead of the normal equations we can also use the Matlab \ command:
c = A\y
c = 2×1
5.5000
-1.5000
Problem 5
f = @(x) x^3+x-11;
(a) Secant method
x0 = 3; x1 = 2;
x2 = x1 - f(x1)*(x1-x0)/(f(x1)-f(x0))
x2 = 2.0500
(b) Newton method
fp = @(x) 3*x^2 + 1; % f'(x)
x0 = 2;
x1 = x0 - f(x0)/fp(x0)
x1 = 2.0769
(c) Use fzero: Note that and have different signs. Hence there is a solution in the interval . (Since the function f is strictly increasing, and the solution is unique.)
xs = fzero(f,[2,3])
xs = 2.0743
Problem 6
Define the function :
f = @(x) [4*x(1)+x(1)^2*x(2)-4; 4*x(2)-x(1)*x(2)^2-3];
Perform one step of the Newton method starting with :
x0 = [1;0];
b = f(x0)
b = 2×1
0
-3
A = fp(x0)
A = 2×2
4 1
0 4
d = -A\b % solve linear system A*d = -b
d = 2×1
-0.1875
0.7500
x1 = x0 + d
x1 = 2×1
0.8125
0.7500
Iterate Newton method until :
x = [1;0]
x = 2×1
1
0
while 1
b = f(x);
if norm(b,1)<=1e-10
break
end
A = fp(x);
d = -A\b;
x = x + d;
end
x
x = 2×1
0.8369
0.9316
normf = norm(b,1)
normf = 8.8818e-16
Use fsolve (with default settings):
xs = fsolve(f,[1;0])
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>