フィルターのクリア

How can I fix this problem?

1 回表示 (過去 30 日間)
Okan SENER
Okan SENER 2023 年 12 月 17 日
編集済み: Torsten 2023 年 12 月 17 日
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

回答 (2 件)

Torsten
Torsten 2023 年 12 月 17 日
編集済み: Torsten 2023 年 12 月 17 日
You call "fsolve" with a vector of initial values of length 4, but within your function fonk1, you expect a vector x of length 5 as input. This is not consistent.

Paul
Paul 2023 年 12 月 17 日
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.

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by