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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

per isakson
per isakson am 21 Jan. 2019
Bearbeitet: per isakson am 21 Jan. 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?

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by