Matrix is singular or badly scaled
Show older comments
I am trying to evaluate a recursive equation by means of a for loop with ten iterations. The first column will be the initial 3x1 matrix value (1 1 1) . The last column of the 10x3 matrix will be the final answer. I am getting the message : Warning: Matrix is singular, close to singular or badly scaled.
This is my code :
%Inputting values of X
X = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
%Inputting values of Y
Y = [1.9595, 5.0506, 6.3539, 7.4091, 8.3835, 8.2193, 9.3298, 9.9221, 9.2768, 9.3684]
%Plotting Scatter Diagram
scatter(X,Y);
%Initial values and equations
A = [1; 1; 1]
C = zeros(3,9)
B = [ A C]
f = @(B,X,i) B(1,i).*log((B(2,i).*X(:,i))+B(3,i));
r = @(B,X,Y,i) Y(:,i) - f(B,X,i);
J = @(B,X,i) [-log(B(2,i).*X(:,i)+B(3,i)) , -B(1,i).*X(:,i)./(B(2,i)*X(:,i)+B(3,i)) , -B(1,i)./(B(2,i).*X(:,i)+B(3,i))]
%For loop to perform 10 iterations
for i = 1:9
%Recursive Equation
B(:,i+1) = B(:,i) - (inv((J(B,X,i)'*(J(B,X,i))))*J(B,X,i)'*r(B,X,Y,i));
end
disp(B)
Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!