0% found this document useful (0 votes)
189 views

Matlab Tutorial 1

Here are the steps to solve this problem in MATLAB: 1. Write out the force balance equations: 2000 = k1*x1 + k2*(x1-x2) + k3*(x2-x3) + k4*(x3-0) 2. Define the spring constants: k1 = 150; k2 = 50; k3 = 75; k4 = 225 3. Set up and solve the system of equations in MATLAB This will give the displacements x1, x2, x3 that satisfy equilibrium. Application Problem 3 Consider the following system of three masses connected by springs: m1 = 2 kg m2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

Matlab Tutorial 1

Here are the steps to solve this problem in MATLAB: 1. Write out the force balance equations: 2000 = k1*x1 + k2*(x1-x2) + k3*(x2-x3) + k4*(x3-0) 2. Define the spring constants: k1 = 150; k2 = 50; k3 = 75; k4 = 225 3. Set up and solve the system of equations in MATLAB This will give the displacements x1, x2, x3 that satisfy equilibrium. Application Problem 3 Consider the following system of three masses connected by springs: m1 = 2 kg m2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Quiz 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:

a) What are the dimensions of the matrices?


b) Identify the square, column, and row matrices.
c) What are the values of the elements?
a12 b23
d32 e22
f12 g12
Perform the following
operations:
NUMERICAL METHODS WITH
APPLICATIONS
(MEC500)

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;

v = sqrt (g * m / cd) * tanh (sqrt (g * cd /m) * t)


Number format
Normally MATLAB displays numerical results with about five digit, but
this can be changed with the format command:
◦ format long switches to 16-digit display
◦ format short Switches to 5-digit display
Number format
To print formatted output, use the fprintf
function:
fprintf(‘format’,list)
where format contains formatting specifications
and list is the list of items to be printed, separated
by commas. Typically used formatting
specifications are
◦ %w.df Decimal format
◦ %w.de Scientific format with lowercase
◦ %w.d Integer format
◦ \n Start new line
Exercise 2: for loop (increasing
value)
Find the values of equation
1
num  1  m  100
(m  1)
for


 >> 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

n1 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

The drag coefficient is equal to 12.5kg/s. By using MATLAB, calculate



v(t) from t=0 till t=14. Also plot a graph v versus t.
Jpeg format
Solution: [email protected]

%Define the variable


g = 9.81;
m = 68.1;
c = 12.5;
t = [0:2:14];

% 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')

funcname = inline(‘expression’, var1, var2, …)


g = inline('sin(alpha*x)','x','alpha')
Exercise 7:
Creates an inline function to represent the formula:

f = 3sin(2x2)
>> f = inline('3*sin(2*x.^2)')

f=
Inline function:
f(x) = 3*sin(2*x.^2)

>> argnames(f) >> formula(f) >>char(f)

ans = ans = ans =


'x' 3*sin(2*x.^2) '3*sin(2*x.^2)'
Example of case study
THE CASE OF SIMPLE PENDULUM AND THE
EULER- CROMER METHOD
The Case of Simple Pendulum
and the Euler- Cromer Method
Consider the case of simple pendulum with length l, in restoring force of
gravity with acceleration g. In the approximation that the pendulum is
not driven with large angle θ, the Newton’s second law provides the
equation of motion:
d 2 g
2   
dt l

A numerical solution to the problem based upon approximation of two


first order differential equations:
 d g
 
dt l
d

dt
The Case of Simple Pendulum
and the Euler- Cromer Method

For a desired number of time steps ∆t, repeat the following steps:
g
wi 1  i  i t
l
i 1  i  i 1t
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

% define initial displacement


theta(1)=0.2;
Solution using the Euler-Cromer
method
for step = 1:npoints-1 % loop over the timesteps
omega(step+1) = omega(step) - (g/length)*theta(step)*dt;
theta(step+1) = theta(step) + omega(step+1)*dt
time(step+1) = time(step) + dt;
end

plot(time,theta,'r' ); %plots the numerical solution in red


xlabel('time (seconds) ');
ylabel('theta (radians)');
Solution using the Euler-Cromer
method
Instead of using Euler’s
method

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.

Determining the equations of


motion from Fx max for each
mass using its free-body
diagram results in the
following differential
equations:
Application Problem 1
where k1 = k4 = 10 N/m, k2 = k3 = 40 N/m, and m1 = m2 = m3 = 1 kg. The
three equations can be written in matrix form:

0 = {Acceleration vector} +
[k/m matrix]{displacement vector x}

At a specific time where x1 = 0.05 m, x2 = 0.04 m, and x3 = 0.03 m, this


forms a tridiagonal matrix. Use MATLAB to solve for the acceleration of
each mass.
Application Problem 2
Idealized spring-mass systems
have numerous applications
throughout engineering.
Figure P12.33 shows an
arrangement of four springs in
series being depressed with a
force of 2000 kg.
Application Problem 2
At equilibrium, force-balance equations can be developed defining the
interrelationships between the springs,

where the k’s are spring constants. If k1 through k4 are 150, 50, 75, and
225 N/m, respectively, compute the x’s.

You might also like