An introduction
[X,Y] = meshgrid(-10:0.25:10,-10:0.25:10);
f = sinc(sqrt((X/pi).^2+(Y/pi).^2));
mesh(X,Y,f);
axis([-10 10 -10 10 -0.3 1])
xlabel('{\bfx}')
ylabel('{\bfy}')
zlabel('{\bfsinc}
({\bfR})')
hidden off
MATlab: It’s all about the MATRIX
The truth that you are a slave. Like everyone else you were
born into bondage to overpriced commercial software.
""Let me tell you why you're here.
You're here because you know
something. What you know you can't
explain, but you feel it."
FF KK1111UU
R K U
R K 2121U
"I didn't say it would be easy, Neo. I
just said it would be the truth""
"But I believe that, as a species,
human beings define their reality
through suffering and misery"
T0(1)=100;
%
% INCIDENCE MATRICES AND ASSEMBLY
I=zeros(2,(E+1),(E+1));
for a=1:E
I(1,a,a)=1;
I(2,(a+1),a)=1;
end
I2=zeros(2,(E+1));
for a=1:E
I2(:,:)=I(:,:,a);
K=K+I2'*KE*I2;
M=M+I2'*ME*I2;
end
%
% DOF CONSTRAINTS AND REDUCTION OF GLOBAL MATRICES
%
bcdof(1)=1; %DOF constraint on global DOF 1
bcval(1)=100; % fixed value for DOF constraint no. 1
for ic=1:1 % loop over BCs
id=bcdof(ic);
val=bcval(ic);
for i=1:(E+1) % loop over total DOFs
F(i)=F(i)-val*K(i,id);
K(id,i)=0;
K(i,id)=0;
end
K(id,id)=0;
F(id)=val;
Using Matlab
• Command line
• Text files/m-files
• Everything is a matrix:
A 6
>> A=6
>> A='QWERTY' A QWERTY
>> A=3e5 A 300000
Basics
Matrix input
• Square brackets
>> A=[1,3,6;2,7,8;0,3,9] • Comma or space separates
- Colons
>> A=1:2:9 A 1 3 5 7 9
- Initialisation
>> A=zeros(3,3) >>A=eye(4)
1 0 0 0
0 0 0
0 1 0 0
A 0 0 0 A
0 0 1 0
0 0 0 0 0 0 1
Matrix Algebra
1 2 5 6
A B
3 4 7 8
>> C=A+B;
- Addition/subtraction
>> C=A-B;
- Matrix multiplication
>> C=A*B;
-Element-by-element operations
>> C=A.*B
5 12
C
21 32
Special Functions
>> A’
- Matrix transpose >> inv(A)
- Matrix inverse >> size(A)
-Matrix size
gives
b=1
b=2
b=3
…
b=10
Programming Constructs
If statements
b=input('Give me a number ');
if (b>0)
i_say_that='bigger than zero';
elseif (b<0)
i_say_that ='less than zero';
else
i_say_that ='exactly zero';
end
i_say_that
Less than (b<0)
Greater than (b>0)
Equal to (b==0)
Not equal to (b~=0)
Less than or equal to (b<=0)
etc…
There will always be errors
Matlab is usually quite helpful in reporting errors
• Undefined variables
• Division by zero
• Array indices used wrongly or out of range
• Programme gets stuck in a loop
So...
• Build programmes up gradually, testing after each
change to check there are no errors
• Use comments “% Comment”
• “Hi1, Hi2, Hi3”
STATIC, LINEAR TRUSSES
Materials
1. Number nodes and elements Element section properties
…
2. For each element
Nodal coordinates
• Calculate K(e) , T(e) and Λ(e) matrices
Element
• Transform K(e) into global coordinates
connectivity
• Expand K(e) with incidence matrices
• Expand F(e) with incidence matrices
Element stiffness
matrix K(e)
3. Sum Ks and Fs to form global stiffness
matrix and global load vector Transformation
matrix T(e)
4. Partition K using BCs
Element
5. Solve for unknown displacements U incidence
matrices Λ(e)
6. Back-substitute to solve for unknown R
Loads
7. Use displacement solution to calculate
element forces/stresses Boundary
conditions
NOTATION
E2 u 2x
1,0,3
u 2y
1m
N2 U 2,2,2
u 3x 3,0,0
u 3y 4,3,0
E1 u 4x
E4
2m
u 4y
E3 1000 N
N3
N4
[ELEMENT,NODE1,NODE2]
E5
2m 1m DOFs
ELEMENTS
Local --> Global
A=0.01m2 1,1,3 ũ1x(1) --> 1
2,1,2 ũ1y (1) --> 2
E=210 GPa
3,2,3 ũ2x (1) --> 5
4,2,4 ũ2y(1) --> 6
5,3,4 …
ũ2y(4) --> 8
LOCAL REPRESENTATION
u2t
u2a
2
1 …for element e
u1t
u1a
u1a f1a
1 0 1 0
u1t f1t
U (e) F (e)
(e) EA 0 0 0 0
f2a K
u2 a l (e) 1 0 1 0
u2 t f 2t
0 0 0 0
2a. CALCULATING LOCAL MATRICES
• Local stiffness matrix for each • Local transformation matrix for
element depends on length: each element depends on
inclination to positive x-axis:
(e) ( e ) ~ ( e ) (+θ = anti-
1 0 1 0 U T U clockwise )
(e)
(e) EA 0 0 0 0 cos sin ( e ) 0 0
K
l (e) 1 0 1 0 (e) sin (e)
cos ( e ) 0 0
T (e) (e)
0 0 0 0 0 0 cos sin
(e) (e)
0 0 sin cos
• Incidence matrices map the 4 local
to 8 global degrees of freedom:
4x1 = (4x8) x (8x1)
~ (e) ~
~(e)
(e)
U U
1 0 0 0 0 0 0 0 ũ1x(1) --> 1
(1) 0 1 0 0 0 0 0 0 …because ũ1y(1) --> 2
… ũ2x(1) --> 5
0 0 0 0 1 0 0 0
ũ2y(1) --> 6
0 0 0 0 0 1 0 0
2b. TRANSFORM LOCAL STIFFNESS MATRICES
~ (e) T (e)
K T K T
4x4= 4x4 4x4 4x4
F K11 K12 U
R K 21 K 22 0
F K11U
R K 21U
7. CALCULATE ELEMENT FORCES
ALSO…