Fixing Matrix error and plotting error

3 visualizaciones (últimos 30 días)
Daniel Sode
Daniel Sode el 6 de Jul. de 2020
Comentada: KSSV el 6 de Jul. de 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 comentarios
madhan ravi
madhan ravi el 6 de Jul. de 2020
It’s in fact cumsum(A) / 2
KSSV
KSSV el 6 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by