Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Undefined function problem - lenght
Replies: 1   Last Post: Jan 11, 2014 10:49 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 matheus ramos Posts: 1 Registered: 1/11/14
Undefined function problem - lenght
Posted: Jan 11, 2014 8:02 PM
 Plain Text Reply

Hi all,

Well, the needed variables are not being calculated and therefore, the graph is not plotted. Can anyone help me with this one? For any reason, only s1, sd1 and sdd1 values are calculated and matlab is giving me the following error:

Undefined function 'lenght' for input arguments of type 'double'.
Error in Tutorialq1 (line 40)
s2=zeros(1,lenght(tau2));

I just started using matlab and have no idea what to do.

clc; clear all; close all;

% Description: Given the equations regarding the movement, the program is
% going to calculate the parameters (space, velocity and acceleration) and
% alocate the results in matrices. After that, the program is going to plot
% the graphic of the space, velocity and acceleration. The results of the
% parameters must be saved in a text file.

% Given:
A=500; % acceleration mm/sec^2
D=-500; % deceleration mm/sec^2
F=100; % feedrate (velocity) mm/sec
L=50; % travel length mm

Ts=0.001; % sampling period sec

T1=F/A; % from equation 2
T3=-F/D; % from equation 3
T2=L/F - (T1+T3)/2; % from equation 4

%obs: tau1, tau2, tau3 and s,sd,sdd vary over time, whereas T1,T2,T3 and
%the other parameters are constant.

if T1<0 || T2<0 || T3<0 % Physical impossibility - ERROR message
disp('Error: acceleration, deceleration and travel length are not kinematically compatible.');

else
% create row vector for time, initial time : step size : final time
tau1=0:Ts:T1;
tau2=0:Ts:T2;
tau3=0:Ts:T3;

% preallocate arrays for speed
s1=zeros(1,length(tau1));
sd1=zeros(1,length(tau1));
sdd1=zeros(1,length(tau1));

s2=zeros(1,lenght(tau2));
sd2=zeros(1,lenght(tau2));
sdd2=zeros(1,lenght(tau2));

s3=zeros(1,lenght(tau3));
sd3=zeros(1,lenght(tau3));
sdd3=zeros(1,lenght(tau3));

% from equation 1
for index=1:length(tau1)
s1(index)=F*tau1(index)*tau1(index)/2/T1;
sd1(index)=F*tau1(index)/T1; % first derivative
sdd1(index)=A; % second derivative: acceleration
end
for index=1:length(tau2)
s2(index)=F*tau2(index) + F*T1/2;
sd2(index)=F;
sdd2(index)=0;
end
for index=1:length(tau3)
s3(index)=-F*tau3(index)*tau3(index)/2/T3 + F*tau3(index) + L - F*T3/2;
sd3(index)=-F*tau3(index)/T3 + F;
sdd3(index)=D;
end
end

t1=tau1'; % change tau1 from a row to a column vector tau1'
t2=tau2(2:end)' + T1; % shift bounds and drop first vector element
t3=tau3(2:end)' + T1 + T2;
t = [t1;t2;t3]; % concatenation of time vector

s1=s1';
s2=s2(2:end)';
s3=s3(2:end)';
s = [s1;s2;s3]; % concatenation of displacement vector

sd1=sd1';
sd2=sd2(2:end)';
sd3=sd3(2:end)';
sd = [sd1;sd2;sd3]; % concatenation of the velocity vector

sdd1=sdd1';
sdd2=sdd2(2:end)';
sdd3=sdd3(2:end)';
sdd = [sdd1;sdd2;sdd3]; % concatenation of the acceleration vector

figure(1);
subplot(3,1,1);
plot(t,s)
title('A Simple Trajectory');
ylabel('displacement [mm]');
xlabel('Time [msec]')
subplot(3,1,2);
plot (t,sd);
subplot(3,1,3);
plot (t,sdd);

% save data to file
data = [t s sd sdd]; % t and s should be column vectors
save ex1_data.txt -ASCII -DOUBLE data
%-- End of File --%

Date Subject Author
1/11/14 matheus ramos
1/11/14 Kevin Ellis

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.