Array indices must be positive integers or logical values.
Afficher commentaires plus anciens
code was working then it stopped, been at this for hours need some help
d = 0.1;
L = 2;
r = d/2;
ne = 8;
le = L/ne; % Assuming constant element length
A = pi*r^2;
p = 0.95;
E = 10^6;
nodes = linspace(0, L, ne+1);
elements = zeros(ne, 2);
for i = 1:ne
elements(i, :) = [i, i+1];
end
properties = E*A/le*ones(ne, 3); % Properties matrix: [E, A, le]
K = zeros(ne+1);
for i = 1:ne
k = properties(i, 1)*[1, -1; -1, 1]/properties(i, 3);
K(elements(i, :), elements(i, :)) = K(elements(i, :), elements(i, :)) + k;
end
F = zeros(ne+1, 1);
F(end) = -1000;
K([1, end], :) = 0;
K(1, end) = 1;
K(1, end) = 1;
% part a
displacement = u(end);
reaction= -K(1,:)*u;
disp(displacement)
disp(reaction)
% % part b
% F = zeros(ne+1, 1);
% F(end)=F(end)-1000;
% K([1, end], :) = 0;
% K(1, 1) = 1;
% K(end, end) = 1;
%
% displacements = u(end);
% reactions= -K(1,:)*u;
%
% disp(displacements)
% disp(reactions)
Réponses (1)
The variable u is not defined in your code, but if it exists in your workspace and is empty, then the line
displacement = u(end);
would produce the error you reported.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!