Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB "Mathematical Laboratory" Designed for numerical computation.

Similar presentations


Presentation on theme: "MATLAB "Mathematical Laboratory" Designed for numerical computation."— Presentation transcript:

1 MATLAB "Mathematical Laboratory" Designed for numerical computation

2 Getting Started with MATLAB Start Software Start typing… No compiling

3 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

4 MATLAB Advantages II Active developer community cookbooks, on-line help Add-ons for simulation, electronic measurement, domain-tailored models Graphics built-in Fairly cheap as a student/researcher $200 for research license through Queen's $5,000 commercially!

5 Disadvantages Commercial (not universally available) Not compiled hand-made loops are slower often negated by fast matrix operations Slow to start, bulky Hard to integrated unit tests as tightly as in Java, C

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

7 How to do it Create vectors x = [1 2 3 4 5] y = 3:10 z = 0:2:20 w = linspace(0, 100, 5000)

8 Create Matrices a = ones(10, 5) b = zeros(3, 3) c = eye(5,3)

9 Modify Matrices a * 3 c' a(1, 1) = 4 a(2, 3) = 9 a(:, 2) = 7

10 Combining matrices m1 = ones(3, 5) m2 = 3*ones(3, 5) m1 + m2 m1 * m2 m1.* m2 m1 * m2'

11 Other operations m2^2 m2.^2

12 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?

13 More complex operations Eigenvalues d = diag([1, 3, 6]) eig(d) [v1, v2] = eig(d) sum(d)

14 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)

15 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);

16 Resources MATLAB Help 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/ind ex.html?BB=1

17 Before next Tuesday If you have a Windows laptop, and a ~2 gigs of space, install a complete version of Cygwin


Download ppt "MATLAB "Mathematical Laboratory" Designed for numerical computation."

Similar presentations


Ads by Google