Fixing Matrix error and plotting error

조회 수: 4 (최근 30일)
Daniel Sode
Daniel Sode 2020년 7월 6일
댓글: KSSV 2020년 7월 6일
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
madhan ravi
madhan ravi 2020년 7월 6일
It’s in fact cumsum(A) / 2
KSSV
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by