Indices on the left side are not compatible with the size of the right side

1 visualizzazione (ultimi 30 giorni)
I'm trying to get something to plot, but get the error message "unable to perform assignment because the indices on the left side are not compatible with the size of the right side" at the Va(n) part (4th line up from end of the loop). I'm thinking that this is because n are integers and t isn't? Or is it something else that's gone wrong?
%begin with specifying constants
AB=0.6;
BC=0.1;
BG=0.08;
AG=AB-BG;
omega=120*pi; %for now since there is no angular accel, omega is constant
%two revolutions at 120pi rpm takes 1/30 seconds
for n=1:10000
t=linspace(0,1/30, 10000)
theta=omega.*t; %assuming theta starts at 0
%since Vb=Vc+Vbc,
Vbx=omega.*BC.*sin(theta);
Vby=omega.*BC.*cos(theta);
%using trig:
Vb=omega*BC;
%let zetaAB=zeta*k (the unit vector) where zeta is some unknown
%using sine rule with AB and BC:
zeta=omega*(cos(theta)/sqrt(36-sin(theta).^2));
%let tau=angle CAB
tau=acos(sqrt(36-sin(theta).^2)/6);
%since Va=Vb+Vab
%Vax=omega*BC*sin(theta)+zeta*AB*sin(tau)
%Vay=omega*BC*cos(theta)-zeta*AB*cos(tau)
%Vay=0 because there is no vertical movement at A, only horizontal so
%Vax=Va
%rearranging for zeta then subbing into Vax (along with AB) gives:
Va(n)=0.1.*omega.*sin(theta).*(1+(cos(theta))./sqrt(36-sin(theta).^2));
%Vg can be found in a similar fashion to be:
Vg(n)=sqrt((Va-zeta.*AG.*sin(tau))+zeta.*AG.*cos(tau));
end
%plot the graph
plot(t,Va,t,Vg)
xlabel("time elapsed (s)")
ylabel("magnitude (m/s)")
axis tight
grid on
title('Task 1, Part a')

Risposte (1)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH il 7 Dic 2019
the problem is because you do not need to use the loop for:
%begin with specifying constants
AB=0.6;
BC=0.1;
BG=0.08;
AG=AB-BG;
omega=120*pi; %for now since there is no angular accel, omega is constant
%two revolutions at 120pi rpm takes 1/30 seconds
t=linspace(0,1/30, 10000)
theta=omega.*t; %assuming theta starts at 0
%since Vb=Vc+Vbc,
Vbx=omega.*BC.*sin(theta);
Vby=omega.*BC.*cos(theta);
%using trig:
Vb=omega*BC;
%let zetaAB=zeta*k (the unit vector) where zeta is some unknown
%using sine rule with AB and BC:
zeta=omega*(cos(theta)/sqrt(36-sin(theta).^2));
%let tau=angle CAB
tau=acos(sqrt(36-sin(theta).^2)/6);
%since Va=Vb+Vab
%Vax=omega*BC*sin(theta)+zeta*AB*sin(tau)
%Vay=omega*BC*cos(theta)-zeta*AB*cos(tau)
%Vay=0 because there is no vertical movement at A, only horizontal so
%Vax=Va
%rearranging for zeta then subbing into Vax (along with AB) gives:
Va=0.1.*omega.*sin(theta).*(1+(cos(theta))./sqrt(36-sin(theta).^2));
%Vg can be found in a similar fashion to be:
Vg=sqrt((Va-zeta.*AG.*sin(tau))+zeta.*AG.*cos(tau));
figure
plot(t,Va,t,Vg)
xlabel("time elapsed (s)")
ylabel("magnitude (m/s)")
axis tight
grid on
title('Task 1, Part a')

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by