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 Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by