Matlab Code Ex2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

clc;

clear;

%Input
E = 70e6;
A = 50e-6;
L = 5;
P = 8;
q = 12.5;
%Solution
k1 = A*E* [1/(L) -1/(L);
-1/(L) 1/(L)];

r1 = [q*L/2 q*L/2];

%Assemble global matrix


K = zeros(2);
K(1:2, 1:2) = K(1:2, 1:2) + k1;

R1 = zeros(2,1);
R2 = zeros(2,1);
R2(1:2) = R2(1:2) + r1';

%Point load,P at end of bar


R1(2) = R1(2) + (P/2);
R2(2) = R2(2) + (P/2);

%Solve global displacement


U = zeros (2,1);
U1(2) = K(2,2)\R1(2);
U2(2) = K(2,2)\R2(2);

U = (U1+U2)/2

%FEM solution
%Internal force or reaction
b1 = k1*[U1(1);U1(2)]
b2 = k1*[U2(1);U2(2)] - r1'

%Internal stress
sig1 = b1/A
sig2 = b2/A

You might also like