File Exchange

image thumbnail

Truss Analysis

version 1.0 (92.9 KB) by

A very simple M-file for analysis of any truss

19 Ratings



No License

A very simple M-file for analysis of any truss (2-D & 3-D), calculating of forces, deflections , reactions and drawing the truss and deformation shape

Comments and Ratings (23)

John Snow

Thank you.


Daniel (view profile)

Does it matter if I input the loads and distances in metric? The example is in imperial

Danial Talebi

Thank you Dr.Rahami
He is the best teacher.

I had this chance in my life to being his student.

I learned from you and I wrote my code in structural analysis

op op

op op (view profile)


I cannot get this program to run with a simple truss I am trying to use and I cannot figure out what is wrong with the data.

Coord=[0 16.25 0;16 16.25 0;24 16.25 0;0 0 0;8 0 0;24 0 0]; % coordinates of nodes
Con=[1 2;2 3;2 5;4 5;5 6;3 6];
Re=[1 1 1;0 0 1;0 0 1;1 1 1;0 0 1;0 0 1];
Load=zeros(size(Coord)); Load(6,:)=[0 -10 0];
%Load=[0 0 0;0 -1e5 0;0 0 0;0 -1e5 0;0 0 0;0 0 0];
E=ones(1,size(Con,1))*102000; %*1e7; % Elasticity ( Youngs Modulous)
%E=[1 1 1 1 1 1 1 1 1 1]*1e7;
A=[.25 .25 .25 .25 .25 .25];

The output:
F =

0 0 0 0 0 12.2596

U =

1.0e+13 *

0 0 0 0 0 0
0 0 -5.7399 0 0 -5.7399
0 0 0 0 0 0

R =

0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

Chris Jobes

Very concise code, a bit hard to understand for a novice without a lot of work, but pretty straight forward for those of us in the field. I decided to compare it to a MATLAB script that I wrote based upon Moaveni's book many years ago. It was not nearly as concise, but much more understandable.

I do have an issue with the ST.m code, however. There appears to be an error that only appears if a load is applied to a node that has constrained movement in that direction.

A quick check of the applied loads and reaction force sums should yield 0 in the x and y directions. In one of my test scripts, it did not. The test was a roof truss with snow load concentrations applied at the upper nodes. Two of those nodes had vertical constraints where the truss rested on the wall top plates and the reaction forces I calculated using this script were incorrect.

The fix is easily made and only appears in an odd case. Line 9 should be:


since R=KU-F. I have not yet tested your MSA code, but at a glance, it appears to have the same issue.

Otherwise, great job.

tong mu

Frank McHugh

Frank McHugh (view profile)

For the convience of those who found this code to obtuse, I've uploaded a copy with the ST function reformatted and extensive comments added at
No actual code changes but should be easier to understand, and have confidence in this code

Jeffrey Kantor

Jeffrey Kantor (view profile)

Amazingly brief, but hard to decipher. Sorry to be a killjoy, but this would be better if the functions included even minimal comments and documentation, and was written for clarity rather than brevity.

mohan l

Thanks for sharing this excellent script. I have used it for two years now in my Mechanical Design course (~60 students each). The students find difficulties in the Help.doc document but otherwise the code is robust, simple and fast to solve trusses.

helen joli

Charlie Seviour


Emilio Elli

ali yaseri


mohamad ordelalu

tanks alot

navid amiry

thanks for this file

Ali Özgül

+Publis M-files application and theory (1)
+Graphical program interface (5)
+Workable program description (2)
+Works references (3)

+M-files complexity (4)
+Mlint error message (5)
+Help problems (2)
+Filename of clashes (5)
+Clone the code line (5)
+Program's symbolic manuscript (3)
+Program samples and runing test (3)
+System requirements (5)
+Program running speed (5)

Files archive:
Seleceted file name (3)
Per files comment (3)
All files usefuly (4)

Nice works, I think needs improvements.
Good works.

Menza T

Nicely written.

anjo mirend

great works :) thanks

edurzimo porteynizm

that's very brief! excelent



Adding an image

Draw Truss and Deformation Shape

Plot The Truss

Changing Category


A New Help

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Truss Analysis/