# MENG 421 Lecture 8

The following material accompanies the MENG 421 lecture for February 11, 2004.
Lectures

Examination 1: Monday, February 16, 2004 | 2001 Exams

Good Matlab programming

p2 = -40e3               % use e notation
len = [0.5 0.3 0.2]      % element lengths
not
p2 = -40000              % hard to read
len = [.5 .3 .2]         % leading zero for less than 1
===================
% print the results
fprintf('\n           Axial5 ')
fprintf('\n   Your name, MENG 421, ')
disp(date)

fprintf('\n   Node Displacement    Force')
fprintf('\n           Meter        Newton\n')
for i = 1:length(df)
fprintf('    %2.0f  %10.2e %12.2e \n',i,displ(i),force(i)) <======= Good
end

fprintf('\n   Elem    Stress')
fprintf('\n           Pascal\n')
for i = 1:length(df)-1
fprintf('    %2.0f   %10.2e \n',i,stress(i)) <======= Good
end

Axial5

Node Displacement    Force
Meter        Newton
1  -2.98e-011    2.40e+004
2  -2.98e-004   -4.00e+004
3   7.79e-004   -1.40e+004
4   2.13e-003    3.00e+004

Elem    Stress
Pascal
1   -1.19e+008
2    2.52e+008
3    4.72e+008

############

Poor Matlab formatting,
misaligned decimal points (increase width)
too many digits

fprintf('\n   Node Displacement    Force')
fprintf('\n           Meter        Newton\n')
for i = 1:length(df)
fprintf('    %2.0f  %8.2e %12.2e \n',i,displ(i),force(i)) <======= Poor
end

fprintf('\n   Elem    Stress')
fprintf('\n           Pascal\n')
for i = 1:length(df)-1
fprintf('    %2.0f   %10.2f \n',i,stress(i)) <======= Poor
end

Axial5

Node Displacement    Force
Meter        Newton
1  -2.98e-011    2.40e+004
2  -2.98e-004   -4.00e+004
3  7.79e-004   -1.40e+004
4  2.13e-003    3.00e+004

Elem    Stress
Pascal
1   -119366207.32
2   251504107.60
3   471570201.75

#############

fprintf('\n   Node Displacement    Force')
fprintf('\n           Meter         Kn\n')
for i = 1:length(df)
fprintf('    %2.0f  %10.2e %10.2f \n',i,displ(i),force(i)/1000) <======= Good
end

fprintf('\n   Elem    Stress')
fprintf('\n            MPa\n')
for i = 1:length(df)-1
fprintf('    %2.0f   %8.2f \n',i,stress(i)/1e6) <======= Good
end

% Poor formatting, Use 1e6 not 10^6

fprintf('\n   Node Displacement    Force')
fprintf('\n           Meter         Kn\n')
for i = 1:length(df)
fprintf('    %2.0f  %10.2e %10.2f \n',i,displ(i),force(i)/10^3) <======= Poor
end

fprintf('\n   Elem    Stress')
fprintf('\n            MPa\n')
for i = 1:length(df)-1
fprintf('    %2.0f   %8.2f \n',i,stress(i)/10^6) <======= Poor
end

Axial5

Node Displacement    Force
Meter         Kn
1  -2.98e-011      24.00
2  -2.98e-004     -40.00
3   7.79e-004     -14.00
4   2.13e-003      30.00

Elem    Stress
MPa
1    -119.37
2     251.50
3     471.57

============

MENG 421 | ARMiller | FEA Sites | Reserve books | Ansys | Lectures | Labs