Unable to perform assignment because the left and right sides have a different number of elements.

1 visualización (últimos 30 días)
function [t,v]= Partc ( m,c,g,t0,v0,tn,n )
fprintf('values of t approximations v(t)\n')
fprintf('%8.3f',t0)
fprintf('%19.4f\n',v0)
h=(tn-t0)/n;
t=[t0:h:tn];
v=zeros(1, n);
v(1)=v0;
for i=1:n
v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t/m)));
fprintf('%8.3f',t(i+1));
fprintf('%19.4f\n',v(i+1));
end
plot(t,v)
end
Line 10: (( v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t/m))); keeps giving me the "Unable to perform assignment because the left and right sides have a different number of elements" error. Any help would be appreciated.

Respuestas (1)

per isakson
per isakson el 21 de En. de 2019
Editada: per isakson el 21 de En. de 2019
Maybe replace
v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t/m)));
by
v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t(i)/m)));
v(i+1) is a scalar, I assume, thus the rhs should be a scalar.
Does that make sense?

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by