Why is my script not working?
Show older comments
I keep getting this same error:
Warning: Matrix is close to singular or badly
scaled. Results may be inaccurate. RCOND =
8.154826e-18.
> In originalfailure (line 61)
clear all; clc;
pi=4.0*atan(1.0);
%scalar knowns
r1=4.8;
r2=2.0;
r6=3.63;
t1=-pi;
t5=-pi/2;
t6=0;
%input theta 2
t2= 283*pi/180;
%guess values of scalar unknowns
r3=3.0;
r4=11.0;
r5=4.0;
t3=5.236;
t4=5.236;
%vector containing initial guesses:
x0=[r3;r4;r5;t3;t4];
x=[0;0;0;0;0];
% counter to limit iterations
counter = 0;
counterLimit = 1e3;
while abs(x-x0) >= 1e-2
counter = counter+1;
ct2=cos(t2);
st2=sin(t2);
ct3=cos(t3);
st3=sin(t3);
ct4=cos(t4);
st4=sin(t4);
%compute functions at current guessed values
f1=r2*ct2-r3*ct3+r1;
f2=r2*st2-r3*st3;
f3=r6-r4*ct4+r1;
f4=-r5-r4*st4;
f5=t4-t3;
%define vector for computed functions of guessed values
f=[f1;f2;f3;f4;f5];
%calculate partial derivatives of f w.r.t. each element of x
dfdr3=[-ct3; 0; 0; r3*st3; 0];
dfdr4=[-st3; 0; 0; -r3*ct3; 0];
dfdr5=[0; -ct4; 0; 0; r4*st4];
dfdt3=[0; -st4; -1; 0; r4*ct4];
dfdt4=[0; 0; 0; -1; 1];
% Define the A matrix
A= [dfdr3 dfdr4 dfdr5 dfdt3 dfdt4];
%use equation (2.67) to compute the solution x
x=-inv(A)*f+x0;
r3=x(1,1);
r4=x(2,1);
r5=x(3,1);
t3=x(4,1);
t4=x(5,1);
end
if counter == counterLimit
warning('Failed')
end
fprintf(' %f\n', x);
1 Comment
James Tursa
on 25 Oct 2019
Your iterative scheme appears to be diverging.
Accepted Answer
More Answers (0)
Categories
Find more on Linear Predictive Coding 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!