matlab "mathematical laboratory" designed for numerical computation
TRANSCRIPT
![Page 1: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/1.jpg)
MATLAB
"Mathematical Laboratory"Designed for numerical computation
![Page 2: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/2.jpg)
Getting Started with MATLAB
Start SoftwareStart typing… No compiling
![Page 3: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/3.jpg)
MATLAB Advantages I
Underlying data structure is a matrix common operations on matrices are often
one line long
Built for scientific work libraries include wide range of useful
mathematical and scientific functions
Can be used interactively easy to experiment, little programming
overhead
![Page 4: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/4.jpg)
MATLAB Advantages II
Active developer community cookbooks, on-line help
Add-ons for simulation, electronic measurement, domain-tailored modelsGraphics built-inFairly cheap as a student/researcher $200 for research license through Queen's $5,000 commercially!
![Page 5: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/5.jpg)
Disadvantages
Commercial (not universally available)Not compiled hand-made loops are slower often negated by fast matrix operations
Slow to start, bulkyHard to integrated unit tests as tightly as in Java, C
![Page 6: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/6.jpg)
What it can do
The basic calcs for the beam distortion: function w = computeEulerW(L, q, k) N = 10000; dx = L/N; w4 = k*q * dx * ones(N, 1); % do integration w3 = cumsum(w4);
Beam model calculations can all be done in 4 lines, plus setup code.
![Page 7: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/7.jpg)
How to do it
Create vectors x = [1 2 3 4 5]
y = 3:10
z = 0:2:20
w = linspace(0, 100, 5000)
![Page 8: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/8.jpg)
Create Matrices
a = ones(10, 5)
b = zeros(3, 3)
c = eye(5,3)
![Page 9: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/9.jpg)
Modify Matrices
a * 3
c'
a(1, 1) = 4
a(2, 3) = 9
a(:, 2) = 7
![Page 10: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/10.jpg)
Combining matrices
m1 = ones(3, 5)m2 = 3*ones(3, 5)m1 + m2
m1 * m2
m1 .* m2
m1 * m2'
![Page 11: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/11.jpg)
Other operations
m2^2
m2.^2
![Page 12: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/12.jpg)
Plotting
x = linspace(-5, 5, 1000);y = exp(- x.^2); % why .^2?plot(x, y);
x = -5:5;y = exp(-x.^2); plot(x, y);
% What does plot do with the coords% in x and y?
![Page 13: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/13.jpg)
More complex operations
Eigenvalues d = diag([1, 3, 6]) eig(d) [v1, v2] = eig(d)
sum(d)
![Page 14: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/14.jpg)
Functions
Create a new squareroot.m file function y = squareroot(x) y = sqrt(x);
Run it in MATLAB x = linspace(0, 100); y = squareroot(x); plo(x, y)
![Page 15: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/15.jpg)
Functions in ODE solving
Newton's law of Heating and cooling DE is dy/dt = -k (y – T)
In heat_de.m function dy_dt = heat_de(t, y) k = 0.05; T = -5; % const, ext. temp dy_dt = -k * (y – T);
Solve in MATLAB ode45(@heat_de, [0, 72], 23);
![Page 16: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/16.jpg)
Resources
MATLAB Help <F1> in MATLAB Has full description and examples for all functions
MathWorks website (Developers of MATLAB) http://www.mathworks.com/
On-line tutorial http://www.mathworks.com/academia/student_center/
tutorials/index.html?BB=1
![Page 17: MATLAB "Mathematical Laboratory" Designed for numerical computation](https://reader036.vdocuments.mx/reader036/viewer/2022082409/5697c02c1a28abf838cd9093/html5/thumbnails/17.jpg)
Before next Tuesday
If you have a Windows laptop, and a ~2 gigs of space, install a complete version of Cygwin