ECOR 2606 Lecture 10: ECOR 2606 DE - Jan 10 2018
ECOR 2606 D/E - Lecture 2 - 01/10/2018
Introduction to MATLAB
% - used for comments
y = linspace(x1, x2, n); – creates vector of n evenly spaced points from x1 to x2
ex. >> y1 = linspace(0, 10, 6);
will return y = 0 2 4 6 8 10 ( interval is from 1 to 10 and increases in increments of 6 )
y = linspace(x1, x2); – creates vector of 100 evenly spaced points from x1 to x2
v = zeros (size(t)); - creates array of t zeros
Before starting, do the following:
>>clear -will clear previous entries
>> clc – will delete all text shown
Matlab Code to Produce a Graph
tMax = 20; % maximum time
m = 69.1; g = 9.81; cD = 0.25;
% Euler solution
n = 21; % number of points (including initial point)
deltaT = tMax / (n -1); % interval width
t = linspace(0, tMax, n);
v = zeros (size(t));
for i = 2:n
v(i) = v(i - 1) + (g - ((cD / m) * v(i - 1)^2)) * deltaT;
end
% analytical solution
tFine= linspace(0, tMax, 100);
vCalc = sqrt(g * m / cD) * tanh(sqrt(g * cD/ m) * tFine);
plot (t, v, 'r-o', tFine, vCalc, 'k');
title ('Skydiver Velocity vs Time');
xlabel ('Time (seconds)');
ylabel ('Velocity (m/s)');
grid on
Built in Constants
- pi
- i =
find more resources at oneclass.com
find more resources at oneclass.com
- j =
Note: Do’t use i ad j as outers
Root Finding Problems
Ex. A room is 4m longer than it is wide. The area of the room is 20m^2. What is the area of the room?
Let x be the width of the room. Then the area of the room is x(x+ 4) = x^2+ 4x
Equating this to the given area gives x^2 + 4x = 20
Rearranging gives x^2+ 4x –20 = 0
General Form: Find x such that f(x) = 0
-Values of x where f(x) = 0 are the roots of f(x)
For our problem f(x) is quadratic and the roots can be found using the quadratic formula.
roots = x1, x2 =
If the quantity under the square root is zero the roots are equal.
If this quantity is negative the roots are complex numbers. Matlab code is shown below:
>> a = 1;
>> b = 4;
>> c = -20;
>> disc = b^2 - 4 * a * c;
>> x1 = (-b + sqrt(disc)) / (2 * a)
x1 = 2.8990
>> x2 = (-b - sqrt(disc)) / (2 * a)
x2 = -6.8990
For our problem the root that matters (the one with physical meaning) is clearly 2.8990
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Ecor 2606 d/e - lecture 2 - 01/10/2018. % - used for comments y = linspace(x1, x2, n); creates vector of n evenly spaced points from x1 to x2 ex. >> clc will delete all text shown. Matlab code to produce a graph tmax = 20; % maximum time m = 69. 1; g = 9. 81; cd = 0. 25; Note: do(cid:374)"t use i a(cid:374)d j as (cid:272)ou(cid:374)ters. A room is 4m longer than it is wide. Let x be the width of the room. Then the area of the room is x(x+ 4) = x^2+ 4x. Equating this to the given area gives x^2 + 4x = 20. General form: find x such that f(x) = 0. Values of x where f(x) = 0 are the roots of f(x) For our problem f(x) is quadratic and the roots can be found using the quadratic formula. (cid:4666)(cid:4667)=(cid:1853)2 +(cid:1854)+(cid:1855) roots = x1, x2 = (cid:3029) (cid:3029)2 4(cid:3028)(cid:3030)