[英]Building newton iteration in MATLAB
I seem to get the error "Warning: Matrix is singular to working precision."我似乎收到错误“警告:矩阵对工作精度来说是奇异的。” when trying to get delta_x.尝试获取 delta_x 时。 It should be using 5x1 and 5x5 matrices.它应该使用 5x1 和 5x5 矩阵。
clc; close all; clear all;
phi = 1;
delta_x = 1;
error = 10e-15;
x = [ 0; 0; 0; 0; 0];
n =1;
B =0.025;
while norm(phi)>= error && norm(delta_x) >= error
G = [ 40e3 -20e3 -20e3 0 1; -20e3 20e3 0 0 0; -20e3 0 20e3 0 0; 0 0 0 0 0; 0 0 0 0 0];
fx = [ 0;
B*((-x(4)-0.7)*(x(2)-x(4))-(((x(2)-x(4))^2)/2));
B*((-x(4)-0.7)*(x(3)-x(4))-(((x(3)-x(4))^2)/2));
-B*((-x(4)-0.7)*(x(2)-x(4))-(((x(2)-x(4))^2)/2))- B*((-x(4)-0.7)*(x(3)-x(4))-(((x(3)-x(4))^2)/2));
0];
b = [ 0; 0; 0; 200e-6; 2.5];
dfx = [ 0 0 0 0 0;
0 -B*(0.7+x(2)) 0 B*(0.7+x(4)) 0;
0 0 -B*(0.7+x(3)) B*(0.7+x(4)) 0;
0 B*(0.7+x(2)) B*(0.7+x(3)) -2*B*(0.7+x(2)) 0;
0 0 0 0 0];
phi = G*x + fx - b;
m = G + dfx;
delta_x = -m\phi;
x = x+delta_x;
norm_delta_x(n) = norm(delta_x);
norm_phi(n) = norm(phi);
n = n+1;
end
The dimensions of matrices 5x1 and 5x5 are fine, but what you are doing in the step delta_x = -m\\phi
is solving for an inverse of matrix m
.矩阵 5x1 和 5x5 的维度很好,但是您在delta_x = -m\\phi
步骤中delta_x = -m\\phi
是求解矩阵m
的逆。 Since m
is a matrix that is singular (try running det(m)
and you will get a zero), an inverse matrix does not exist.由于m
是一个奇异矩阵(尝试运行det(m)
并且您将得到零),因此不存在逆矩阵。 Matlab sees this and notifies you by telling you "Matrix is singular to working precision". Matlab 看到了这一点,并通过告诉您“矩阵对工作精度而言是奇异的”来通知您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.