ដូត វណ្ណី(០៥)
លំ ហាត់ទ១
ី ប្រព័ន្ធសមកា
ី រលីនន្អ រ៊ែ 3 នេរ
#Mathblab code
clear all;
clc;
% Iterative method for linear system Ax = b
% Jacobi iteration : A = D - (E + F)
% Input A and b
A = [4 -1 0;
-1 4 -1;
0 -1 4];
b = [3 2 3]';
n = length(b);
% Decomposition
D = [4 0 0;
0 4 0;
0 0 4];
E = [0 0 0;
-1 0 0;
0 -1 0];
F = [0 -1 0;
0 0 -1;
0 0 0];
% Jacobi matrices
B = inv(D)*b;
MJ = inv(D)*(E + F);
% Initial estimation
x = [0 0 0]';
% Iteration
N = 10;
for k = 1:N
x = B + MJ*x;
end
x
លំ ហាត់ទ២
ី
�#Mathblab code
clear all;
clc;
% Newton-Raphson method
f = @(x) x^3 + 2*x + 1;
df = @(x) 3*x^2 + 2;
% Initial guess in [-1,0]
x = -0.5;
% Iteration
N = 5;
for k = 1:N
x = x - f(x)/df(x);
end
x
#Answer