Azzera filtri
Azzera filtri

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 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Geoff Hayes
Geoff Hayes il 14 Giu 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".

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by