Fixing Matrix error and plotting error
1 次查看(过去 30 天)
显示 更早的评论
Having trouble with the matrix and plotting the N vs displacement I have attached my code Line 23 is where the isuue is
clear all
clc
%clg
%hold off
axis normal
% Tapering aluminum bar under its own weight
E = 200E9; % Pa
L = 1.0; % m
rho = 77000*9.81; % N/m^3
N =[1,2,4,8,16]; % Number of elements
% Compute element length, area, k and force
for i=1:N+1
w(i)=100-(0.075*(i-1)*L);
A(i)=w(i).^2;
end
for i = 1:N
Aavg(i)=(A(i+1)+A(i))/2;
end
for i = 1:N
x(i) = L/N*i;
k(i) = (Aavg(i)*E/L);
F(i) = (rho*Aavg(i)*L/2);
end
% Assembly of the stiffness matrix using k's.
K = zeros(N,N);
K(1,1) = k(1) + k(2);
K(1,2) = -k(2);
for i = 2:N-1
K(i,i-1) = -k(i);
K(i,i) = k(i) + k(i+1);
K(i,i+1) = -k(i+1);
f(i,i-1) = -F(i);
f(i,i) = F(i) + F(i+1);
f(i,i+1) = -F(i+1);
end
K(N,N-1) = -k(N);
K(N,N) = k(N);
f(N,N-1) = -F(N);
f(N,N) = F(N);
% Solve for displacements {q}. It is a column vector.
q = inv(K)*F';
plot([0 N],[0; q],'-g',N,q,'g.');
hold on
title('Effect of Discretization');
xlabel('Number of Elements');
ylabel('Axial deformation (m)');
2 个评论
KSSV
2020-7-6
Your code is a mess.....needs lot of changes....
Note:
N is a vector, and you are using it in iteration, i = 1:N, this is not correct.....and many more corrections needed.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!