Fixing Matrix error and plotting error

1 vue (au cours des 30 derniers jours)
Daniel Sode
Daniel Sode le 6 Juil 2020
Commenté : KSSV le 6 Juil 2020
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 commentaires
madhan ravi
madhan ravi le 6 Juil 2020
It’s in fact cumsum(A) / 2
KSSV
KSSV le 6 Juil 2020
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by