How can I fix this problem?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone, I wrote an analysis code of a conveyor line (it looks like crank-connecting rod mechanism) but I saw these mistakes in picture. How can I fix the problem? You can see my code in attach. Thanks a lot.
clc;
clear;
clear all;
global L1 L2 L3 L4 L5 theta1 theta2 theta3 theta4 w1
L1=1; L2=4; L3=3; L4=3.2; L5=6.5; %metre cinsinden uzuv uzunlukları
theta1=165*(pi/180); theta2=(0:1:360)*(pi/180); theta3=(129.732)*(pi/180); theta4=(14.12)*(pi/180); %radyan cinsinden açılar
ar=6:length(theta2)-5
N = length(theta2); %adım sayısı
x = zeros (4,N); %bilinmeyen açılar bulunur bu matrise kaydedilir
for i = 1:N
theta2 = theta2(i); %radyan cinsinden Teta_2 açısı
if i == 1
x0 = 1*[165*pi/180;0*pi/180;129.732*pi/180;14.12*pi/180]
else
x0 = x(:,i-1);
end
opt=optimset('TolFun',1e-6,'TolX',1e-6,'Display','off');
x(:,i) = fsolve(@fonk1,x0,opt);
end
theta1 = x(1,:);
theta2 = x(2,:);
theta3 = x(3,:);
theta4 = x(4,:);
[theta1(ar)' theta2(ar)' theta3(ar)' theta4(ar)']*180/pi; %derece cinsinden açılar
% ANÄ°MASYON
%figure
for i = 1:N;
A = L1*[cos(theta2(i)) sin(theta2(i))];
B = L2*[cos(theta3(i)) sin(theta3(i))];
C = L3*[cos(theta1(i)) sin(theta1(i))];
D = L4*[cos(theta3(i)) sin(theta3(i))];
E = L5*[cos(theta4(i)) sin(theta4(i))];
Ax(i)=A(1); Ay(i)=A(2);
Bx(i)=B(1); By(i)=B(2);
Cx(i)=C(1); Cy(i)=Cy(2);
Dx(i)=D(1); Dy(i)=Dy(2);
Ex(i)=E(1); Ey(i)=Ey(2);
AB = [A;B]';line(AB(1,:),AB(2,:))
BC = [B;C]';line(BC(1,:),BC(2,:))
CD = [C;D]';line(CD(1,:),CD(2,:))
DE = [D;E]';line(DE(1,:),DE(2,:))
BE = [B;E]';line(BE(1,:),BE(2,:))
text(A(1),A(2),'A')
text(B(1),B(2),'B')
text(C(1),C(2),'C')
text(D(1),D(2),'D')
text(E(1),E(2),'E')
axis([-5000 5000 -5000 5000])
drawnow
if i<N, clf;
end
end
k = 180/pi; %radyandan dereceye dönüştürme
hold on;
plot (Bx,By,'k.' , Ax,Ay,'k.')
figure;
plot (k*theta3,Bx,'k.' , k*theta3,By,'k.')
xlabel('theta3(derece)');
legend('B_x' , 'B_y')
figure;
plot (k*theta3,Ax,'k.' , k*theta3,Ay,'c.')
xlabel('theta3(derece)');
legend('A_x' , 'A_y')
figure;
k = 180/pi; %radyandan dereceye dönüştürme
plot(k*theta1(ar),k*theta2(ar));
xlabel('theta2(derece)');
ylabel('theta1(derece)');
% AÇISAL HIZLAR
W1 = 1*ones(1,N);
for i = 1:n
w1 = W1(i);
theta1=theta1(i);
theta2=theta2(i);
theta3=theta3(i);
theta4=theta4(i);
if i == 1
x0 = [0 0 0 0] %Başlangıç değerleri
else
x0 = x(:, i-1);
end
end
W1 = x(1,:); W2 = x(2,:); W3 = x(3,:); W4 = x(4,:); W5 = x(5,:);
[(180/pi)*theta1(ar)' W1(ar)' W2(ar)' W3(ar)' W4(ar)' W5(ar)'] %açısal hızlar (rad/s)
fu=gradient(theta3,theta1);
W3=W1.*fu;
fu=gradient(theta2,theta1);
W2=W1.*fu
figure;
subplot(1,2,1);
plot(theta1(ar)*k, W3(ar), 'k.');
legend('W_3')
subplot(1,2,2);
plot(theta1(ar)*k,W2(ar), 'k.');
legend('W_2')
function F = fonk1(x) %konum analizi
global L1 L2 L3 L4 L5 theta1 theta2 theta3 theta4 w1
W1=x(1); W2=x(2); W3=x(3); W4=x(4); W5=x(5);
j = sqrt(-1);
CD1 = L1*j*W1*exp(j*theta2) + L2*j*W2*exp(j*theta3) + L3*j*W3*exp(j*theta1);
CD2 = L3*j*W3*exp(j*theta1) + L4*j*W4*exp(j*theta4) + L5*j*W5*exp(j*theta4);
F = [real(CD1);
imag(CD1);
real(CD2);
imag(CD2)];
end
function F = fonk2(x) %hız analizi
W1=x(1); W2=x(2); W3=x(3); W4=x(4); W5=x(5);
j = sqrt(-1);
CD1 = L1*j*W1*exp(j*theta2) + L2*j*W2*exp(j*theta3) + L3*j*W3*exp(j*theta1);
CD2 = L3*j*W3*exp(j*theta1) + L4*j*W4*exp(j*theta4) + L5*j*W5*exp(j*theta4);
F = [real(CD1);
imag(CD1);
real(CD2);
imag(CD2)];
end
0 comentarios
Respuestas (2)
Paul
el 17 de Dic. de 2023
The variable x is defined at the top of the code to have 4 rows. In the loop that calls fsolve, x0 is defined with four elements on the first iteration and is assigned from a column of x on subsequent iterations. So fsolve is expecting that fonk1 operates on a 4-element vector input. But fonk1 tries to assign x(5) to W5, which results in the error because the input from fsolve to fonk1 only has four elements.
0 comentarios
Ver también
Categorías
Más información sobre Polar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!