# How do I solve the following system of equations in MATLAB using generalized Newton's method with epsilon being equal to 1e-6, I also need?

need to find the optimal overrelaxation factor w which is optimal if it converges the fastest to some initial value whatever it might be. The equations are as follows:

x[j-1]-2x[j]+x[j+1]=0 j=3...98

-2x[1]+x[2]=5

x[1]-2x[2]+x[3]=-4

x[98]-2x[99]+x[100]=-8

x[99]-2x[100]=13

j in brackets is a subscript

Relevance
• ooorah
Lv 6
2 years ago

The best way to do it: not using Newton's method.

A = zeros(100, 100); % Coefficients

b = zeros(100, 1); % "Answers"

A(1, 1:2) = [-2 1]; % First equation

b(1) = 5;

A(2, 1:3) = [1 -2 1]; % Second equation

b(2) = -4;

for k = 3:98 % 3rd through 98th equation

A(k, k-1:k+1) = [1 -2 1];

end

A(99, 98:100) = [1 -2 1]; % 99th equation

b(99) = -8;

A(100, 99:100) = [1 -2]; % 100th equation

b(100) = 13;

x = A\b; % Solution

Source(s): Solving system of linear equations in MATLAB: https://www.mathworks.com/help/symbolic/solve-a-sy...