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

1 vue (au cours des 30 derniers jours)
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.

Réponses (1)

per isakson
per isakson le 21 Jan 2019
Modifié(e) : per isakson le 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?

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by