MFiles Functions Examples
MFiles Functions Examples
11/21/2024 1
OUTLINE
• M-Files
• Functions
• Create functions
• Call the functions
• Examples
11/21/2024 2
M-Files
• M-Files
11/21/2024 3
Functions
You can create the functions in seperate files only if you save the file with the
same name of the function.
You may create the functions in the script files at the end of your codes and
call them in the same *.m-file.
11/21/2024 4
Examples
• Ex 1:
11/21/2024 5
Examples
• Ex 2:
Using the Dikdortgen.m function for a beam with L= 5 m span and w= 10
N/m uniformly distributed load acting on it, calculate the stresses at top
and bottom fibers. b=30 cm, h=60 cm.
𝑤∙𝐿2 𝑀𝑚𝑖𝑑 ∙𝑐
𝑀𝑚𝑖𝑑 = 8
; −𝜎𝑡𝑜𝑝 = 𝜎𝑏𝑜𝑡 = 𝐼
clc
clear all Sub program
close all
[A, I, C, xg, yg]=Dikdortgen(0.3,0.6)
w=10; % N/m
L=5; % m
Mmid=w*L^2/8;
Sigma_top=-Mmid*yg/I;
Sigma_bot=Mmid*yg/I;
disp(['Sigma_top=',num2str(Sigma_top),' N/m^2'])
disp(['Sigma_top= ',num2str(Sigma_bot),' N/m^2']) Sigma_top=-1736.1111 N/m^2
Sigma_top= 1736.1111 N/m^2
11/21/2024 6