Getting the Error "Not enough input arguments" but I did the exact same method earlier in the code without issue..
조회 수: 1 (최근 30일)
이전 댓글 표시
clear all
close all
clc
% EMEC-342 Mini Project: 4-Bar Linkage Analysis
% Known Values
a=10; % cm
b=25; %cm
c=25; %cm
d = 20; % cm
AP=50; % cm
n=a/2;
q=c/2;
delta2=0;
delta3=0;
delta4=0;
w2=10; %rad/sec
alpha2=0;
oc=1;
t2=zeros(1,361); % rotation angle theta2 of O2A
for (i=1:361)
t2=i-1;
end
% Calculation of K1,K2,K3,K4,K5
K1=d/a;
K2=d/c;
K3=(a^2-b^2+c^2+d^2)/(2*a*c);
K4=d/b;
K5=(c^2-d^2-a^2-b^2)/(2*a*b);
%% Matlab Functions
function f=Grashof(lengths)
u=sort(lengths);
if((u(1)+u(4))<(u(2)+u(3)))
f=1;
elseif (u(1)+u(4))==(u(2)+u(3))
f=0;
else
f=-1;
end
end
%% Functions for calculation of angular orientations theta3, theta4
% of links AB and O4B
% Calculation of A
function AA=A(K1,K2,K3,t2)
AA=cos(t2)-K1-K2*cos(t2)+K3;
end
% Calculation of B
function BB=B(t2)
BB=-2*sin(t2);
end
% Calculation of C
function CC=C(K1,K2,K3,t2)
CC=K1-(K2+1)*cos(t2)+K3;
end
% Calculation of angular orientation theta4
function t4=theta4(K1,K2,K3,t2,oc)
AA = A(K1,K2,K3,theta2);
BB = B(theta2);
CC = C(K1,K2,K3,theta2);
t4=2*atan((-BB+oc*sqrt(BB^2-4*AA*CC))/(2*AA));
end
% Calculation of D
function DD=D(K1,K4,K5,t2)
DD=cos(t2)-K1+(K4*cos(t2))+K5;
end
% Calculation of E
function EE=E(t2)
EE=-2*sin(t2);
end
% Calculation of F
function FF=F(K1,K4,K5,t2)
FF=K1+(K4-1)*cos(t2)+K5;
end
% Calculation of angular orientation theta3
function t3=theta3(K1,K4,K5,t2,oc)
DD=D(K1,K4,K5,t2);
EE=E(t2);
FF=F(K1,K4,K5,t2);
t3=2*atan((-EE+oc*sqrt(EE^2-4*DD*FF))/(2*DD));
end
%% Functions for calculation of angular speeds omega3, omega4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
function as=angSpeed(a,b,c,w2,t2,t3,t4)
as=[w2*a/b*sin(t4-t2)/sin(t3-t4),w2*a/c*sin(t2-t3)/sin(t4-t3)];
end
%% Position Vectors
function r=RAO2(a,t2)
r= [a*cos(t2),a*sin(t2)];
end
function r=RPA(AP,t3,delta3)
r=AP*[cos(t3+delta3),sin(t3+delta3)];
end
function r=RPO2(a,PA,t2,t3,delta3)
r=RAO2(a,t2)+RPA(PA,t3,delta3);
end
%% Functions for calculation of angular acceleration alpha3, alpha4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
% Calculation of G
function GG=G(c,theta4)
GG=c*sin(theta4);
end
% Calculation of H
function HH=H(b,theta3)
HH=b*sin(theta3);
end
% Calculation of I
function II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4)
II=(a*alpha2*sin(t2))+(a*w2^2*cos(t2))+(b*omega3^2*cos(theta3))-(c*omega4^2*cos(theta4));
end
% Calculation of J
function JJ=J(c,theta4)
JJ=c*cos(theta4);
end
% Calculation of K
function KK=K(b,theta3)
KK=b*cos(theta3);
end
% Calculation of L
function LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4)
LL=(a*alpha2*cos(t2))+(a*w2^2*sin(t2))+(b*angSpeed(1)^2*sin(theta3))-(c*angSpeed(2)^2*sin(theta4));
end
function aa=angAccel(G,H,I,J,K,L)
GG=G(c,theta4);
HH=H(b,theta3);
II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4);
JJ=J(c,theta4);
KK=K(b,theta3);
LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4);
aa=[(II*JJ-GG*LL)/(GG*KK-HH*JJ),(II*KK-HH*JJ)/(GG*KK-HH*JJ)];
end
%% Trace Point Velocity
function v=VA(a,w2,t2)
v=[-a*w2*sin(t2),a*w2*cos(t2)];
end
function v=VPA(AP,angSpeed,theta3,delta3)
v=AP*[-angSpeed(1)*sin(theta3+delta3),angSpeed(1)*cos(theta3+delta3)];
end
function v=VPO2(a,w2,angSpeed,t2,theta3,delta3,AP)
v=VA(a,w2,t2)+VPA(AP,angSpeed(1),theta3,delta3);
end
%% Trace Point Acceleration
function a=aA(a,alpha2,t2,w2)
a=[-a*alpha2*sin(t2),-a*w2^2*cos(t2)];
end
function a=APA(AP,angSpeed,theta3,delta3,angAccel)
a=AP*[-angAccel(1)*sin(theta3+delta3),-angSpeed(1)^2*cos(theta3+delta3)];
end
function a=APO2(a,w2,angSpeed,t2,theta3,delta3,AP)
a=aA(a,alpha2,t2,w2)+APA(AP,angSpeed(1),theta3,delta3,alpha3);
end
%% Tracepoint Acceleration N
function aN=ANO2(alpha2,t2,delta2,w2,RNO2)
aN=RNO2*[-alpha2*sin(t2+delta2)-(w2^2*cos(t2+deta2)),alpha2*cos(t2+delta2)-(w2^2*sin(t2+delta2))];
end
%% Plots
% Plot of theta3 and theta4 as functions of theta2
figure(1)
plot(t2,theta3,'r:');
hold on
plot(t2,theta4,'b-');
% Plot of omega3 and omega4 as functions if theta2
figure(2)
plot(t2,angSpeed(1),'r:');
hold on
plot(t2,angSpeed(2),'b-');
% Plot of alpha3 and alpha4 as functions of theta2
figure(3)
plot(t2,angAccel(1),'r:');
hold on
plot(t2,angAccel(2),'b-');
% Plot of RPO2y as a function of RPO2x
figure(4)
plot(RPO2(1),RPO2(2));
% Plot of VPO2x as a function of RPO2x
figure(5)
plot(RPO2(1),VPO2(1));
% Plot of VPO2y as a function of RPO2y
figure(6)
plot(RPO2(2),VPO2(2));
% Plot of magnitude of VPO2 as a function of theta2
figure(7)
VPO2mag=sqrt(v(1,i)^2+v(2,i)^2);
plot(t2,VPO2mag);
% Plot of aPO2x as a function of RPO2x
figure(8)
plot(r(1),a(2));
% Plot of aPO2y as a function of RPO2y
figure(9)
plot(r(2),a(2));
% Plot of VPO2y as a function of RPO2y
figure(10)
aNO2mag=sqrt(aN(1,i)^2+aN(2,i)^2);
plot(t2,aNO2mag);
댓글 수: 1
Stephen23
2024년 9월 16일
편집: Stephen23
2024년 9월 16일
You wrote the function THETA3 to require five input arguments:
% Calculation of angular orientation theta3
function t3=theta3(K1,K4,K5,t2,oc)
...
end
What do you expect to happen when you call THETA3 with zero inputs?:
plot(t2,theta3,'r:');
% ^^^^^^ called with no inputs
채택된 답변
Ayush
2024년 9월 16일
I ran your code and found that the theta3 function is defined to take inputs (K1, K4, K5, t2, oc). You need to call this function with these parameters before using it in the plot.
I hope this helps!
댓글 수: 3
Stephen23
2024년 9월 16일
편집: Stephen23
2024년 9월 16일
"It seemed to be the remedy at first, but after changing that for every plot I seem to get the same error all over again"
Because exactly the same mistake still occurs:
plot(t2,angSpeed(a,b,c,w2,t2,theta3,theta4),'r:');
% ^^^^^^ called with zero inputs
You will then have exactly the same problem with THETA4. For exactly the same reason.
And possibly more... you need to check your code. And read the error messages.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!