MATLAB Answers

0

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.

Asked by Wilfredo Huaman on 14 Jun 2019
Latest activity Answered by Geoff Hayes
on 14 Jun 2019
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

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 14 Jun 2019
 Accepted Answer

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".

  0 Comments

Sign in to comment.