Matlab Tutorial 1
Matlab Tutorial 1
https://play.kahoot.it/#/?quizId=c439ced2-12ff-4cc0-ab9d-
28409afe4299
NUMERICAL METHODS WITH
APPLICATIONS
(MEC500)
TUTORIAL 1.0
Defining Matrices
A number of matrices
are defined as
Answer the following questions
regarding these matrices:
TUTORIAL 1.1
Exercise 1: M-file
Determine the velocity of the free-falling bungee jumper where g =
9.81m/s2, m = 68.1 kg, t = 12 s, and cd = 0.25 kg/m.
gm gcd
v tanh( t)
cd m
Do the same calculation but this time use the function for variable input
g = 9.81; m = 68.1;
t = 12; cd = 0.25;
>> num
for m=1:100
num =1/(m+1); num =
end
0.0099
Exercise 3: for loop (decreasing value)
Find the values of equation
1
k
expn100 to 0
from
>> k
for n=100:-2:0
k=1/(exp(n)); k =
end
1
Exercise 4: for loop (with
summation)
Find the values of equation
1000
1
n1 n
2
>> sum
sum = 0;
for n = 1:1000 sum =
sum = sum + 1/(n^2);
end
1.6439
Exercise 5: while loop
Suppose that
x x≥ 0 and
yfor
exx <10
yfor
for x = 2:-1:-3
if x >= 0 1.4142
y = sqrt(x); 1.0000
else 0.0000
y = exp(x)-1; -0.6321
end -0.8647
fprintf('%5.4f\n',y) -0.9502
end
Exercise 6: Problem
solving
A parachutist of mass 68.1 kg jumps out of a stationary hot air balloon.
Given:
gm
v(t) (1 e(c /m )t )
c
% Define the
v = g*m/c*(1-exp(-c/m*t));
plot(t,v)
title(‘Graph v versus t’)
ylabel(‘t (s)’); xlabel(‘v (m/s)’)
grid
Inline function
funcname = inline(‘expression’)
g = inline('t^2')
f = 3sin(2x2)
>> f = inline('3*sin(2*x.^2)')
f=
Inline function:
f(x) = 3*sin(2*x.^2)
For a desired number of time steps ∆t, repeat the following steps:
g
wi 1 i i t
l
i 1 i i 1t
ti 1 ti t
Solution using the Euler-Cromer
method:
length= 1; % pendulum length (m)
g=9.8; % gravity
npoints = 250; % discretize time into 250 interval
dt = 0.04; % time step
omega = zeros(npoints,1); % initializes omega
theta = zeros(npoints,1); % initializes theta
time = zeros(npoints,1); % initializes the vector time
i 1 i i t
NUMERICAL METHODS WITH
APPLICATIONS
(MEC500)
TUTORIAL 1.2
Application Problem 1
Consider the three mass-four
spring system in Figure below.
0 = {Acceleration vector} +
[k/m matrix]{displacement vector x}
where the k’s are spring constants. If k1 through k4 are 150, 50, 75, and
225 N/m, respectively, compute the x’s.