How to find out the remaining iterations of the Newton Raphson Method with Jakobi Matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
KALYAN ACHARJYA
2019년 11월 16일
편집: KALYAN ACHARJYA
2019년 11월 16일
Do the x array indexing, consider x=[......] where x(1) as initial value
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!