How to find out the remaining iterations of the Newton Raphson Method with Jakobi Matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Abir Abbas
el 16 de Nov. de 2019
Comentada: Mohammad Abir Abbas
el 16 de Nov. de 2019
I was doing a transforming a Code in Python to Matlab regarding the Newton Raphson with Jakobi Matrix. How can I optimize this. This code gives me only 1 results for x1 and x2. but there should be 3 more. How to fix this ? What wrong have I done here ?
The Inputs I used is :
f = @(x)[0.5 ∗ cos(x(1)) − 0.5 ∗ sin(x(2)) − x(1); 0.5 ∗ sin(x(1)) + 0.5 ∗ cos(x(2)) − x(2)],
J = @(x)[−0.5 ∗ sin(x(1)) − 1, −0.5 ∗ cos(x(2)); 0.5 ∗ cos(x(1)), −0.5 ∗ sin(x(2)) − 1],
x_0 = [0 0]′, E_tol = 10−4
Output Result is showing:
x = test_1(f,J,x_0,1e-4)
x =
0.2000
0.6000
Main Functional Code:
function x = test_1(f,J,x_0,E_tol)
n =1000; %% How to initialize or do a iteration till n time
x = x_0;
f_val = f(x);
f_norm = norm(f_val);
for k = 0:n
while (abs(f_norm) > E_tol) %% (k<n) >> I want to imply this condition.How to do?
delta_x = linsolve(J(x_0),-f_val);
x = x_0 + delta_x;
f_val = f(x_0);
f_norm = norm(f_val);
k = k+1;
if abs(f_norm) > E_tol %% What else can I do here ?
k = k-1;
x;
break
end
end
end
end
0 comentarios
Respuestas (1)
KALYAN ACHARJYA
el 16 de Nov. de 2019
Editada: KALYAN ACHARJYA
el 16 de Nov. de 2019
Do the x array indexing, consider x=[......] where x(1) as initial value
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!