- #1

- 260

- 21

- Homework Statement
- We are required to solve a system of nonlinear equations in Matlab using both fsolve and Newton's Method. For Newton's Method we must achieve an accuracy of 1e-6 and write down the number of iterations to achieve the accuracy.

- Relevant Equations
- Newton's Method and Fsolve

Here is my code so far and solution.

When using fsolve, we obtain the result that the equation does get solved. We find the values to be 1.0000, 0.0000, and 2.0000. 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 as stated by Matlab. Using Newton’s method from the starting point we get that the system of nonlinear equations does not converge, we're analyzing them so it does not mean there is a solution for this practice problem. I am trying to figure out how to count the amount of iterations and reach an accuracy of 1e-6 so my count may be completely incorrect and I am unsure of how to proceed from here because using fsolve results in me having solutions but using Newton's method, it does not converge, any help would be appreciated.

When using fsolve, we obtain the result that the equation does get solved. We find the values to be 1.0000, 0.0000, and 2.0000. 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 as stated by Matlab. Using Newton’s method from the starting point we get that the system of nonlinear equations does not converge, we're analyzing them so it does not mean there is a solution for this practice problem. I am trying to figure out how to count the amount of iterations and reach an accuracy of 1e-6 so my count may be completely incorrect and I am unsure of how to proceed from here because using fsolve results in me having solutions but using Newton's method, it does not converge, any help would be appreciated.

Matlab:

```
f = @(x) [x(1)^2+x(2)^2+x(3)^2-5 ; x(1)+x(2)-1 ; x(1)+x(3)-3];
fp = @(x) [2*x(1), 2*x(2), 2*x(3); 1, 1, 0; 1, 0, 1];
format long g
x = [(1+sqrt(3))/2; (1-sqrt(3))/2; sqrt(3)]; %starting point
acc = 1e-6;
count = 0;
while abs(x)>acc
b = f(x); % evaluate f
A = fp(x); % evaluate Jacobian
d = -A\b; % solve A*d = -b
x = x + d
count = count + 1;
end
disp(count);
```

Last edited by a moderator: