"Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. " RCOND = NaN. I'm using Newton's Method which uses a Jacobian Matrix for space mech. class. not sure how to fix w/out changing elements of matrix (set)

4 次查看(过去 30 天)
%% Create Guess vector
th4g=45*deg2rad;
th3g=225*deg2rad;
th5g=350*deg2rad;
% [r3 ; r6 ;th3 ; th4 ; th5]
guess = [3;8;th3g;th4g;th5g];
% set up a tolerance value
t=10^-6;
error=2*t;
% Define initial and final input angle
th2_start=200*deg2rad;
th2_end=135*deg2rad;
% generate input vector
n=100;
th2=linspace(th2_start,th2_end,n)';
% matrix to hold results
guess_save = zeros(n,length(guess));
%% Jacobian
for i=1:n
while error > t
% Jacobian Matrix
J1=[-cos(guess(3)) 0 (guess(1)*sin(guess(3))) 0 0];
J2=[-sin(guess(3)) 0 (-guess(1)*cos(guess(3))) 0 0];
J3=[0 -cos(th6) 0 -r4*sin(guess(4)) -r5*sin(guess(5))];
J4=[0 sin(th6) 0 r4*cos(guess(4)) r5*cos(guess(5))];
J5=[0 0 1 -1 0];
J=[J1;J2;J3;J4;J5];
% Calculate the function values
f1=r2*cos(th2(i))-guess(1)*cos(guess(3))-r1*cos(th1);
f2=r2*sin(th2(i))-guess(1)*sin(guess(3))-r1*sin(th1);
f3=r4*cos(guess(4))+r5*cos(guess(5))-guess(2)*cos(th6);
f4=r4*sin(guess(4))+r5*sin(guess(5))-guess(2)*sin(th6);
f5=guess(4)- pi-guess(3);
% make a function vector
FUN=[f1;f2;f3;f4;f5];
% save our initial guess
guess_1=guess;
% calculate the new guess
guess= -J^-1*FUN+guess;
% calculate the error
error=max(abs(guess_1-guess));
end
% reset error
error =2*t;
% save guess value
guess_save(i,:)= guess;
end

回答(1 个)

Sai Sumanth Korthiwada
编辑:Sai Sumanth Korthiwada 2022-12-20
Hi Eileen,
I understand that you are encountering a warning message while working on Newton’s method which uses Jacobian matrix.
Please make the following changes in your code:
%% Create Guess vector
% th4g=45*deg2rad;
% th3g=225*deg2rad;
% th5g=350*deg2rad;
%% Create Guess vector
% Use this:-
th4g=deg2rad(45);
th3g=deg2rad(225);
th5g=deg2rad(350);
Please use 'deg2rad(angle)' instead of 'angle*deg2rad' in the remaining code as well.
Refer to the documentation below for more information on 'deg2rad' function:
Hope this resolves your query.

类别

Help CenterFile Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by