Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 921-by-1.

1 vue (au cours des 30 derniers jours)
Having trouble getting this to work even tho it says it matches in the workspace i = 921 and c = 921x1 double but its give ther error in the for loop that alpha can not run with contains the 921x1 array. Any help would be appreciated.
t=0:i;
theta=zeros(i,1);
omega=zeros(i,1);
alpha=zeros(i,1);
Fr=zeros(i,1);
theta(1,:)=deg2rad(90); % initial angular position
omega(1,:)=0; % initial angular velocity
alpha(1,:)=0; % initial angular acceleration
% Iteratively solve equations of motion using Euler's Method
for n=1:i
theta(n+1,:)=theta(n,:)+omega(n,:)*dt; % new angular position
omega(n+1,:)=omega(n,:)+alpha(n,:)*dt; % new angular velocity
alpha(n+1,:)=(-g*sin(theta(n+1,:)))/L-c(:,1)*omega(n+1,:); % new angular acceleration
Fr(n+1,:)=mass*g*cos(theta(n+1,:))+mass*L*(omega(n+1,:)).^2; % Reaction Force
end

Réponse acceptée

Geoff Hayes
Geoff Hayes le 14 Juin 2019
Wilfredo - it isn't clear which line is throwing the error but piece of code caught my eye
alpha(n+1,:)=(-g*sin(theta(n+1,:)))/L-c(:,1)*omega(n+1,:);
Do you really mean to be using all elements of c or just the nth element? Should this line be
alpha(n+1,:)=(-g*sin(theta(n+1,:)))/L-c(n,1)*omega(n+1,:);
I only ask because the error is telling you that the code is trying to assign a 921x1 array (your c?) into a 1x1 "slot".

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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