When theta2 makes a complete cycle, I get error message.

clear all
clc
L2 = 10;
L3 = 20;
theta2 = 0:pi/18:2*pi;
% theta2 = pi/12;
omega2 = 1.6;
theta3 = (2 * pi) + asin((-L2/L3)* sin(theta2))
L1 = L2 * cos(theta2) + L3 * cos(theta3);
C = [L2*sin(theta2)*omega2;-L2*cos(theta2)*omega2]
D = [-L3*sin(theta3) -1 ;L3*cos(theta3) 0]
B = inv(D) * C
plot(theta2,theta3)
grid on
xlabel('theta2(degrees)')
ylabel('theta3(degrees)')
title('crank angle(theta2) vs link 3 angle(theta3)')
figure
plot(theta2,L1)
grid on
xlabel('theta2(degrees)')
ylabel('L1(m)')
title('crank angle(theta2) vs link 1 angle(L1)')

댓글 수: 3

Ben Rancici
Ben Rancici 2017년 2월 3일
편집: Ben Rancici 2017년 2월 3일
What is the real question here? Are you asking for the community to help you debugging your script? If so, why don't you share with us the error message you get?
Your D is not a square matrix, that's why error popped.
Indeed, if theta2 is a vector, then D is not square and cannot be inverted.

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2017년 2월 3일
clc; clear all ;
clear all
clc
L2 = 10;
L3 = 20;
theta2 = 0:pi/18:2*pi;
% theta2 = pi/12;
omega2 = 1.6;
theta3 = (2 * pi) + asin((-L2/L3)* sin(theta2)) ;
L1 = zeros(1,length(theta3)) ;
for i = 1:length(theta3)
L1(i) = L2 * cos(theta2(i)) + L3 * cos(theta3(i));
C = [L2*sin(theta2(i))*omega2;-L2*cos(theta2(i))*omega2] ;
D = [-L3*sin(theta3(i)) -1 ;L3*cos(theta3(i)) 0] ;
B = D\C ;
end
plot(theta2,theta3) ;
grid on
xlabel('theta2(degrees)')
ylabel('theta3(degrees)')
title('crank angle(theta2) vs link 3 angle(theta3)')
figure
plot(theta2,L1)
grid on
xlabel('theta2(degrees)')
ylabel('L1(m)')
title('crank angle(theta2) vs link 1 angle(L1)')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 3일
When theta2 has a complete cycle from 0 to 2*Pi, then the sin and cos entries go from [0 1] at the beginning, through a bunch of different possibilities and return to [0 1] at the end. Those lead to the entries in D being the same for the first and last element. Duplicate rows in a matrix to be inverted guarantee that the matrix is singular.
You need to end your theta2 just before it completes a cycle to 2*Pi. For example,
theta2 = 0:pi/18:2*pi;
theta2(end) = [];

카테고리

태그

질문:

2017년 2월 2일

댓글:

2017년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by