1
votes

I seem to get the error "Warning: Matrix is singular to working precision." when trying to get delta_x. It should be using 5x1 and 5x5 matrices.

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
1

1 Answers

1
votes

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. Since m is a matrix that is singular (try running det(m) and you will get a zero), an inverse matrix does not exist. Matlab sees this and notifies you by telling you "Matrix is singular to working precision".