Matrix changes size inside for loop prevent making further matrix operations

3 visualizaciones (últimos 30 días)
deph.
deph. el 13 de Sept. de 2020
Comentada: deph. el 15 de Sept. de 2020
Hello,
I've came across a problem where I need to save maximum values of acceleration for different speeds in a vector and then make a acceleration in terms of speed plot.
global m k c g p0 t0 t1 ws;
m = 5000;
k = 800000;
c = 12000;
%c = 0;
g = 9.81;
L = 1;
h = 0.25;
x10 = m*g/k; %static deflection
p0 = h/2; %initial displacement
vc = 1;
step = 0.1;
xttt = zeros(1,150); %matrix for saving max acceleration
vcc = zeros(1, 150); %matrix for saving speed
for q = 1:150
vcc(q) = vc;
v = vc/3.6; %velocity in m/s (input 1km/h)
vc = vc + step;
ws = v/L*2*pi; %frequency for one wavelength (rad/s)
t0 = 2*pi/ws; %damped period?
t1 = t0+L/v; % (L/v) time of traversing the bump
%[T Y] = ode23('EOMfode', [0 15], [x10;0]);
[T, Y] = ode23('EOMfode', [0 15], [x10;0]);
ii = size(T);
for i = 1:ii
p(i) = (T(i)>t0)*(-p0+p0*sin(ws*(T(i)-t0)+pi/2))*(T(i)<t1);
pt(i) = (T(i)>t0)*((-ws)*p0*cos(ws*(T(i)-t0)+pi/2))*(T(i)<t1);
end
xtt = g+c*(pt(:)-Y(:,2))/m+k*(p(:)-Y(:,1))/m;
xttt(q) = max(abs(xtt));
%fground = k*(Y(:,1)-p(:))+c*(Y(:,2)-pt(:));
end
FUNCTION:
function zt = EOMfode(t,z)
global m k c g p0 t0 t1 ws;
p = (t>t0)*(-p0+p0*sin(ws*(t-t0)+pi/2))*(t<t1);
pt = (t>t0)*(-ws)*p0*cos(ws*(t-t0)+pi/2)*(t<t1);
xt = z(2);
yt = g+(c*(pt-z(2))+k*(p-z(1)))/m;
zt=[xt;yt];
size(zt);
Problem is that after 14th iteration I get this error:
Matrix dimensions must agree.
Error in PLOTStest (line 41)
xtt = g+c*(pt(:)-Y(:,2))/m+k*(p(:)-Y(:,1))/m;
My T and Y matrices have a 359 rows while p and pt have 362 rows. What is more, when I delete for q = 1:150 loop and write each speed and run program manually there is no variance in matrices size. Is it a problem with ode23 and function EOMfode? What am I missing?

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by