Workshop of MATLAB. Section 3

Size: px
Start display at page:

Download "Workshop of MATLAB. Section 3"

Transcription

1 Workshop of MATLAB Section 3

2 Outlines Logic and Flow Control Loops Inline and temporary function definition Writing MATLAB Functions and Scripts Debugging Solving Differential Equations Symbolic Math

3 Logic and Flow Control (I) Name Description Symbol eq Equal == ne Not equal <> and ~= lt Less than < gt Greater than > le Less than or equal <= ge Greater than or equal >=» eq(a,b); means A==B» lt(a,b); means A<B» ne(a,b); means A~=B or A<>B or ~(A==B) Both of above expressions could be used in MATLAB. Relation Operation

4 Logic and Flow Control (II) Name Description Symbol Relop AND Relop OR and Circuit logical (Returns true (1) if both inputs evaluate to true, and false (0) if they do not.) Circuit logical (Returns true (1) if either input, or both, evaluate to true, and false (0) if they do not.) Wise logical (Returns true (1) if both inputs is nonzero, and false (0) if they do» or(a,b); xor means Logical EXCLUSIVE OR(Performs an exclusive OR operation on the A B corresponding elements of arrays A and B. The resulting element C(i,j,...) is logical» not(a); means ~Atrue (1) if A(i,j,...) or B(i,j,...), but not both, is nonzero.)» and(a,b); means A&B Both of above expressions could be used in MATLAB. not) or Wise logical (Returns true (0) if both inputs is zero, and false (1) if they do not) not Logical NOT(Returns true (0) if both inputs is nonzero, and false (1) if they do not) && & ~ xor(a,b) any True if any element of vector is nonzero any(a) all True if all elements of vector are nonzero all (A) Logical Operation

5 Logic and Flow Control (III) Logical variable is an array of true and false values» Logic=[true false false true true];» whos Logic Name/Attributes Size Bytes Class m 1x5 5 logical Logical Variables

6 Logic and Flow Control (IV) Symbol Description + Addition or unary plus. - Subtraction or unary minus. * Matrix multiplication..* Array multiplication. / Slash or matrix right division. B/A = B*inv(A)./ Array right division. A./B = A(i,j)/B(i,j) \ Backslash or matrix left division. A\B = inv(a)*b \. Array left division. A.\B = B(i,j)/A(i,j) ^ Matrix power..^ Array power. A.^B = A(i,j) to the B(i,j) power Matrix transpose. A' is the linear algebraic transpose of A. Array transpose. A.' is the array transpose of A Operator Precedence

7 Logic and Flow Control (V) When we want to check for equality between two variables, we might use: A == B This is valid MATLAB code, when A and B are scalars. When A and B are matrices, A == B does not test if they are equal. It tests where they are equal. The result is another matrix of 0 s and 1 s. If A and B are not the same size, then A == B is an error. Logical Indexing for Matrices

8 Logic and Flow Control (VI)» A = magic(4);» B = A;» B(1,1) = 0;» A == B ans = The proper way to check for equality between two variables is to use the isequal function. isequal returns 1 (representing true) or 0 (false).» isequal(a,b) ans = 0 Logical Indexing

9 Logic and Flow Control (VII) isequal: isequal True if arrays are numerically equal. isequal(a,b) returns logical 1 (TRUE) if arrays A and B are the same size and contain the same values, and logical 0 (FALSE) otherwise. If A or B contains a NaN element, isequal returns false because NaNs are not equal to each other isempty: isempty True for empty array. isempty(x) returns 1 if X is an empty array and 0 otherwise. An empty array has no elements Helpful Function if Expression

10 Logic and Flow Control (VIII) if Conditionally execute statements. The general form of the if statement is if expression1 statements1 elseif expression2 statements2 else statements3 End The statements are executed if the real part of the expression has all nonzero elements The ELSE and ELSEIF parts are optional. Zero or more ELSEIF parts can be used as well as nested IF's. If, elseif, else, end

11 Logic and Flow Control (IX) yournumber = input('enter a number: '); if yournumber < 0 disp('negative') elseif yournumber > 0 disp('positive') else disp('zero') end EXAMPLES if B > A 'greater' elseif A < B 'less' elseif A == B 'equal' else error('unexpected Situation') end If, elseif, else, end

12 Logic and Flow Control (X) Switch among several cases based on expression. The general form of the SWITCH statement is: switch switch_expr case case_expr, statement,..., statement case {case_expr1, case_expr2, case_expr3,...} statement,..., statement... otherwise, statement,..., statement end Switch & case

13 Logic and Flow Control (XI) The switch_expr can be a scalar or a string. A scalar switch_expr matches a case_expr if switch_expr == case_expr. A string switch_expr matches a case_expr if strcmp(switch_expr,case_expr) returns 1 (true). If switch_expr matches the case_expr the statements following the case will be executed. Switch & case

14 Logic and Flow Control (XII) When the case expression is a cell array, the case_expr matches if any of the elements of the cell array match the switch expression. If none of the case expressions match the switch expression then the otherwise case is executed. Only one case is executed and execution resumes with the statement after the end. Only the statements between the matching case and the next case, otherwise, or end are executed. Switch & case

15 Logic and Flow Control (XIII) Example: To execute a certain block of code based on what the string, method, is set to, method = 'Bilinear'; switch lower(method) case {'linear','bilinear'} disp('method is linear') case 'cubic disp('method is cubic') case 'nearest disp('method is nearest') otherwise disp('unknown method.') end Switch & case

16 Logic and Flow Control (Exercise) 1. Make MATLAB write something depending on which test our month "passes". [hint: month = input('give month number (1-12): ' ); ] 2. Use the command rem (remainder). The syntax is rem(x,y) and returns the remainder after the division of the two integers x and y. [hint : number = input('give an integer: ' );remainder2 = rem(number,2); remainder3 = rem(number,3); ] 3. Make MATLAB show the number of day that user key in. [Hint : [daynum, daystring] = weekday(date, 'long', 'en_us'); e.g User key in Tuesday, Matlab display Day2. ] Exercise

17 Loops (I) FOR Repeat statements a specific number of times. The general form of a FOR statement is: for variable = expr statement statement end The columns of the expression are stored one at a time in the variable and then the following statements, up to the end, are executed for

18 Loops (II) The expression is often of the form X:Y, in which case its columns are simply scalars. for R = 1:20 for C = 1:20 end end A(R,C) = 1/(R+C-1); Long loops are more memory efficient when the colon expression appears in the for statement since the index vector is never created. for

19 Loops (III) Step S with increments of :0.1 for S = 1.0: -0.1: 0.0 S end Set E to the unit 5:vectors for E = eye(5) E end Set D to a defined vectors V = [ ]; for D = V D end for

20 Loops (IV) It is recommended that you do not assign to the loop control variable while in the body of a loop. for k=1:2 disp(sprintf('at the start of the loop, k = %d', k)) k = 10; disp(sprintf('following the assignment, k = %d\n', k)) end At the start of the loop, k = 1 Following the assignment, k = 10 At the start of the loop, k = 2 Following the assignment, k = 10 for

21 Loops (V) The WHILE loop repeats a group of statements an indefinite number of times. under control of a logical condition. A matching end delineates the statements. The general form of a while statement is: while expression statements end The statements are executed while the real part of the expression has all nonzero elements. while

22 While loop Loops (VI) >> h = 0.001; >> x = [0:h:2]; >> y = 0*x; >> y(1) = 1; >> i = 1; >> size(x) >> max(size(x)) >> while(i<max(size(x))) y(i+1) = y(i) + h*(x(i)-abs(y(i))); i = i + 1; end >> plot(x,y,'go') >> plot(x,y) while

23 Loops (VII) Continue The continue statement passes control to the next iteration of the for loop or while loop in which it appears. Skipping any remaining statements in the body of the loop. Break break terminates the execution of for and while loops. In nested loops, break exits from the innermost loop only. break is not defined outside of a for or while loop. Return return terminates the current sequence of commands and returns control to the invoking function or to the keyboard. return is also used to terminate keyboard mode. jumper

24 Loops (VIII) Continue % The loop below will calculate and print values of k^2-50 % for all values of the requested k % for which k^2-50 is positive. for k=-10:1:10 if (k^2-50<0) continue; end val=k^2-50; fprintf( \n k=%g val=%g,k,val) end jumper

25 Loops (IX) Break % The loop below will calculate values of k^2-50 % for all values of the requested k % until it turns negative for k=-10:1:10 if (k^2-50<0) break; end val=k^2-50; fprintf( \n k=%g val=%g,k,val) end jumper

26 Loops (X) Return % The loop below will calculate values of k^2-50 % for all values of the requested k % terminate once the condition not fullfill for k=-10:1:10 if (k^2-50<0) return; end val=k^2-50; fprintf( \n k=%g val=%g,k,val) end jumper

27 Loops (Exercise) 1. Create a vector x with the elements with FOR loop a. 2, 4, 6, 8,... b. 10, 8, 6, 4, 2, 0, -2, -4 c. 1, 1/2, 1/3, 1/4, 1/5, Create a vector with the elements with WHILE loop a. 2, 4, 6, 8,... b. 10, 8, 6, 4, 2, 0, -2, -4 c. 1, 1/2, 1/3, 1/4, 1/5, Construct a vector containing the squares of the integers 2 through Compute and display the even powers of 2 less than or equal to val. 5. Create an Hilbert matrix, H. [Hint : H(i,j) = 1/(i+j-1)] 6. Produces a vector with the same elements as x, but they are arranged in the reverse order. 7. The program prompts the user to enter any number. If the number is less than 0, the break statement terminates the execution of the loop. If the number is greater than 10, the continue statement skips the value and jumps to the do while loop without terminating the loop. Otherwise, it will print the entered number. Exercise

28 Inline and temporary function definition (I) Inline functions are like function M-files, i.e. they accept (usually numerical) input and return output. inline( expr,arg, n ) In the first command (expr) the formula is edited as a string, i.e. it is quoted by apostrophes. In the second command (arg) the string is evaluated and converted to an inline function. With the third argument (n) we fix the parameter of the inline function. Inline and Temporary Function Definition

29 Inline and temporary function definition(ii) Example: Let's defined the function y(x) introduced symbolically in the previous section as inline function: y= (1+x) 2 /(1+x 2 )» '(1+x).^2./(1+x.^2) ans = (1+x).^2./(1+x.^2)» y= y=inline(ans,'x ) y = Inline function: y(x) = (1+x).^2./(1+x.^2) This function is also array smart w.r.t. x:» y(1),y([1 2 3]) ans = 2 ans = fplot(y,[-1 1]) Inline and Temporary Function Definition

30 Inline and temporary function definition» argnames(y),formula(y) ans = 'x' (III) ans = (1+x).^2./(1+x.^2) Inline and Temporary Function Definition

31 Inline and temporary function definition (Exercise) 1. Define the function y(x)=(1+x) 2 /(1+x 2 ). 2. Define as inline function. Evaluate this function at 4 and plot it on the interval [-5,5]. [tips : fplot function] 3. Make an inline function g(x)=x+cos(x 2 ). Plot it using vector x=-5:.1:5 and y=g(x). Exercise

32 Writing MATLAB Functions and Scripts (I) Inline Function f = inline('sin(x)','x'); Operation and evaluation takes place in the current workspace Script Function function y = f(x) y = sin(x) Operate in separate workspaces Comparison

33 Writing MATLAB Functions and Scripts (II) Projectile Modeling Assume a projectile by initial velocity V=10 m/s and A=60 degree as its angel of throwing calculate time and distance of first contact with earth also and max height in second and meter respectively.» V = 20;» A = 60;» g = 9.8;» Ar = pi*a/180;» Vv = V*sin(Ar);» Vh = V*cos(Ar);» T = 2*Vv/g;» t = 0:.01:T;» H = Vv*t g/2*(t.^2);» D = Vh*t;» plot(d,h);» Hmax = max(h)» Dend = max(d) A Model Example

34 Writing MATLAB Functions and Scripts (III) We already knows command history and its functionality. One of command history capabilities is its ability to save a list of command as an M-file. This M-file could be executed to reproduce our desired result later from command window. A Command History

35 Writing MATLAB Functions and Scripts (IV) Click on third line of modeling assignment (gravity) line. Hold shift key and click on bottom most line of command history. Right-click on selected area and click on Create M-file. Save your M-file as ProjectileModel.m. Close M-file Editor. Creating Script Files

36 Writing MATLAB Functions and Scripts (V) When we save an M-file in current directory we will be able to run it by typing its name in Command Window. Close figure. Type clc to clear Command Window. Type ProjectileModel in command prompt. Press Enter to run your first M-file Running Scripts

37 Writing MATLAB Functions and Scripts (VI) M-files often have a natural structure consisting of multiple sections. For larger files, We typically focus efforts on a single section at a time, working with the code in just that section. Similarly, when conveying information about our M-files to others, often we describe the sections of the code. To facilitate these processes, we can use M-file cells, where cell means a section of code. Specifically, MATLAB software uses cells for: Rapid code iteration in the Editor. This makes the experimental phase of our work with M-file scripts easier. Publishing M-files. This allows us to include code and results in a presentation format such as HTML. Cells

38 Writing MATLAB Functions and Scripts (VII) This is the overall process of using cells for rapid code iteration: In the MATLAB Editor, enable cell mode by selecting Cell > Enable Cell Mode. Define the boundaries of the cells in an M-file script using cell features. Once you define the cells, use cell features to navigate quickly from cell to cell in your file, evaluate the code in a cell in the base workspace, and view the results. Rapid Code Interaction by Cells

39 Writing MATLAB Functions and Scripts (VIII) Cells

40 Writing MATLAB Functions and Scripts (IX) Cells

41 Writing MATLAB Functions and Scripts (Exercise) 1. A very simple model of this would be that we have 100 units in the reservoir and remove 20% each time step (in other words, 20% of the snow melts each day). We can make a script file to calculate the amount of melting and the amount remaining after each day by making the script file melting.m. [hint : need array to store Initial amount in the Reservoir, empty array to hold the Reservoir values] 2. A simple model might be that if the reservoir is less than 30, the melting rate is 30% per day, otherwise it is 20% per day. Plot of the Reservoir and the Melting rate as a function of time by making the script file meltplot.m. [hint : need array to store Initial amount in the Reservoir, empty array to hold the Reservoir values] 3. Write a script file to draw a pretty circle [hint : angle = linspace(0, 2*pi, 360);x = cos(angle);y = sin(angle);] 4. Write a script to sums the first n squares up to n=10 and save in file sumsquares. Exercise

42 Debugging (I) Function echo disp sprintf fprintf whos size keyboard Description Display function or script code as it executes. Display specified values or messages. Display formatted data of different types. List variables in the workspace. Show array dimensions. Interrupt program execution and allow input from keyboard. return warning MException Resume execution following a keyboard interruption. Display specified warning message. Access information on the cause of an error. Debugging

43 Debugging (II) Function dbstop dbclear dbcont dbdown dbmex dbstack dbstatus dbstep dbtype dbup dbquit Description Set breakpoints Clear breakpoints Resume execution Reverse workspace shift performed by dbup, while in debug mode Enable MEX-file debugging (on UNIX platforms) Function call stack List breakpoints Execute one or more lines from current breakpoint List text file with line numbers Shift current workspace to workspace of caller, while in debug mode Quit debug mode Debugging

44 Debugging (III) test.m function a = test(b) c = sqrt(b)*cos(b); a = test1(b,c); >>dbtype test [list the line number] >>dbstop in test [set breaking point] >> test(magic(3)) >> dbstack [display the function calls that led to the breakpoint] >> dbcont [Continue execution of the function] Debugging

45 Debugging (Exercise) Create a vector with the elements with FOR loop 0, 1/2, 2/3, 3/4, 4/5,... for d1=0:4 end for d2=1:5 rats(d3) d3=d1./d2 Try debug Exercise

46 Solving Differential Equations (I) MATLAB has two functions, ode23 and ode45, which are capable of numerically solving differential equations. Solver Problem Type When to Use ode45 Nonstiff Most of the time. This should be the first solver you try. ode23 Nonstiff For problems with crude error tolerances or for solving moderately stiff problems. Differential Equation Solution

47 Solving Differential Equations (II) The syntax for actually solving a differential equation with these functions is:» [T,Y] = ode45(functionname,t0,tf,y0,options); Argument Name functionname T0 and tf y0 >>help odeset Description the name of a function that we write that describes our system of differential equations. the initial and final times that we want a solution for It returns a vector of times, T, and a matrix Y that has the values of each variable in our system. Each column of Y is a different variable. vector of the initial values of the variables in our system of equations >> option = odeset('reltol', 10^-4); options Optional integration argument created using the odeset function. to tighten the default relative The tolerance odeset function from 10^-3 lets to you 10^-4. adjust the integration parameters of the particular ODE solvers. Differential Equation Solution

48 Solving Differential Equations (III) Solve y -2y-1, y(0)=1, for 0<t<10 [T,Y] = ode45( ex1, [0,10], 1); function yprime=ex1(t,y) yprime=2*y-1; Nonlinear Solver

49 Solving Differential Equations (IV) Example (1 st order) dv/dt= -g+4/15*v 2 /m function rk=f(t,y) mass=80; g=9.81; rk=-g+4/15*y^2/mass; Save as f.m >> timerange=[0 30]; >> initialvelocity=0; >> [t,y]=ode45( f,timerange,initialvelocity) >> plot(t,y(:,1)) Type in MATLAB command window Differential Equation Solution

50 Solving Differential Equations (V) Example (2 nd order) Step1: Convert into state space form Let V=y 1 and dv/dt=y 2 Therefore, (d/dt)v= y 2 (d 2 /dt 2 ) y 1 =-2t(y 2 )-9 y 1 Differential Equation Solution

51 Solving Differential Equations (VI) Example (2 nd order) Step2: Create f2.m file function rk=f2(t,y) rk=[y(2); -2*t*y(2)-9 *y(1)]; (d/dt)v= y 2 (d 2 /dt 2 ) y 1 =-2t(y 2 )-9 y 1 Differential Equation Solution

52 Solving Differential Equations (VII) Example (2 nd order) Step3: Run in Matlab command window >> timerange=[0 5]; >> initialvelocity=[0;1]; >> [t,y]=ode45( f2,timerange,initialvelocity) >> plot(t,y) Differential Equation Solution

53 Solving Differential Equations (Exercise_1) 1. Plot the solution to y =2y-1, y(0)=1 and tspan = [0 10]. 2. Plot the solution to y =xy 2 +y with y(0)=1 and tspan = [0 10]. 3. Plot the solution to y +8y +2y=0 with y(0)=0, (d/dt)y(0)=1 and tspan = [0 10]. 4. Plot the solution to (d 2 /dt 2 )y+3*(d/dt)y + 2y=4exp(- 2t) -5 where y(0)=2, (d/dt)y(0)=-1and and tspan = [0 10]. 5. Solve and plot the solution to x +y -2x = 3 where x =0, y =1, x =0 and tspan = [0 10]. Exercise

54 Solving Differential Equations 6. Plot the solution to (Exercise_2) where σ = 10, β = 8/3, and ρ = 28, 1. x(0) = 8, y(0) = 8, and z(0) = 27 and tspan = [0 10]. 7. Plot the solution to Where y 1 (0) =600 and y 2 (0)= 0 Exercise

55 Symbolic Math (I) MATLAB is capable of doing fairly simple symbolic math analysis. It is designed for numerical work, rather than symbolic work, and in order to do symbolic math MATLAB actually uses the engine for another math software product, MAPLE. Every time we're trying to do in MATLAB's symbolic math toolkit involves mostly calling the "maple" command (which simulates Maple). Symbolic Math

56 Symbolic Math (II) For basics, though, the symbolic math toolkit is useful. A symbolic equation in MATLAB is represented as a string, such as» 'x + 2 = 5' The basic symbolic math operations all take string equations as arguments, and return string equations. MATLAB decides which variable in that string is the symbolic variable.» x = sym('x','real'); Could create a symbolic object known as x. Symbolic Math

57 Symbolic Math (III) To clear the symbolic objects x of 'real status, type» syms x clear Basic symbolic functions all work as we would expect, too.» g = ('x^2 + 2*x + 3') MATLAB also has symbolic functions such as int & diff for integrate and differentiate.» int('x^2') - int(expr,var) computes the indefinite integral of expr with respect to the symbolic scalar variable var» diff(g) simplify to simplify an expression.» f = 3*x *x» simplify(f) Symbolic Math

58 Symbolic Math (IV) taylor to generate a taylor series expansion.» syms x;» f = sin(x)/x;» t = taylor(f)» 1-1/6*x^2+1/120*x^4 We can also use solve to solve algebraic equations. solve(x + 1, x) -> 1 dsolve to solve a differential equation. dsolve('dy=y+1','x') -> -1+exp(x)*C1 Symbolic Math

59 Symbolic Math (V) The function numeric('symbolic expression') lets us convert a symbolic representation to numbers wherever possible, which also helps in simplification. Symbolic Math

60 Symbolic Math (VI) The function ezplot('symbolic function ) takes a symbolic equation and plots it as a function of x. We can specify a range or let it use the default. To specify a range, use ezplot('symbolic function',[xmin xmax]'). For more details on the symbolic toolkit by:» help sym. Symbolic Math

61 Symbolic Math (VII) Symbolic Math

62 Symbolic Math (Exercise_1) 1. Create the 3-by-4 symbolic matrix A with the auto-generated elements A1_1,..., A3_4 2. Find the determinant and the trace of the matrix A. [hint : det function and trace function] ] 3. Simplify z=sin 2 (α)+cos 2 (α). 4. Take the derivative of function f(x)=x 3 -cos(x) 5. Integrate function f(x,y).. [hint : int function] Exercise

63 Symbolic Math (Exercise_2) 6. Find the roots of this polynomial, f(x)=2x 3 +4x-8. [hint: solve roots function] 7. Symbolic variable S containing the expression x^2-y^2. Let's factor this expression. [hint : factor function] 8. We want to enter f(x,y)=(4x 2-1)e -x2-y2 as a symbolic expression and compute f(1,2). [hint : subs function] 9. Solve xy +y=2e 2x [hint :Dy= (2/x)*exp(2*x)- y/x] Exercise

Arithmetic operations

Arithmetic operations Arithmetic operations Add/Subtract: Adds/subtracts vectors (=> the two vectors have to be the same length). >> x=[1 2]; >> y=[1 3]; >> whos Name Size Bytes Class Attributes x 1x2 16 double y 1x2 16 double

More information

C/C++ Programming for Engineers: Matlab Branches and Loops

C/C++ Programming for Engineers: Matlab Branches and Loops C/C++ Programming for Engineers: Matlab Branches and Loops John T. Bell Department of Computer Science University of Illinois, Chicago Review What is the difference between a script and a function in Matlab?

More information

Compact Matlab Course

Compact Matlab Course Compact Matlab Course MLC.1 15.04.2014 Matlab Command Window Workspace Command History Directories MLC.2 15.04.2014 Matlab Editor Cursor in Statement F1 Key goes to Help Information MLC.3 15.04.2014 Elementary

More information

Chapter 7: Programming in MATLAB

Chapter 7: Programming in MATLAB The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Computer Programming (ECIV 2302) Chapter 7: Programming in MATLAB 1 7.1 Relational and Logical Operators == Equal to ~=

More information

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 1999 by CRC PRESS LLC CHAPTER THREE CONTROL STATEMENTS 3.1 FOR

More information

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

More information

7 Control Structures, Logical Statements

7 Control Structures, Logical Statements 7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Laboratory 1 Octave Tutorial

Laboratory 1 Octave Tutorial Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory

More information

Relational and Logical Statements

Relational and Logical Statements Relational and Logical Statements Relational Operators in MATLAB A operator B A and B can be: Variables or constants or expressions to compute Scalars or arrays Numeric or string Operators: > (greater

More information

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

What is Matlab? The command line Variables Operators Functions

What is Matlab? The command line Variables Operators Functions What is Matlab? The command line Variables Operators Functions Vectors Matrices Control Structures Programming in Matlab Graphics and Plotting A numerical computing environment Simple and effective programming

More information

Programming in MATLAB

Programming in MATLAB Programming in MATLAB Scripts, functions, and control structures Some code examples from: Introduction to Numerical Methods and MATLAB Programming for Engineers by Young & Mohlenkamp Script Collection

More information

Boolean Logic & Branching Lab Conditional Tests

Boolean Logic & Branching Lab Conditional Tests I. Boolean (Logical) Operations Boolean Logic & Branching Lab Conditional Tests 1. Review of Binary logic Three basic logical operations are commonly used in binary logic: and, or, and not. Table 1 lists

More information

Mathematical Operations with Arrays and Matrices

Mathematical Operations with Arrays and Matrices Mathematical Operations with Arrays and Matrices Array Operators (element-by-element) (important) + Addition A+B adds B and A - Subtraction A-B subtracts B from A.* Element-wise multiplication.^ Element-wise

More information

SBT 645 Introduction to Scientific Computing in Sports Science #3

SBT 645 Introduction to Scientific Computing in Sports Science #3 SBT 645 Introduction to Scientific Computing in Sports Science #3 SERDAR ARITAN serdar.aritan@hacettepe.edu.tr Biyomekanik Araştırma Grubu www.biomech.hacettepe.edu.tr Spor Bilimleri Fakültesi www.sbt.hacettepe.edu.tr

More information

4.0 Programming with MATLAB

4.0 Programming with MATLAB 4.0 Programming with MATLAB 4.1 M-files The term M-file is obtained from the fact that such files are stored with.m extension. M-files are alternative means of performing computations so as to expand MATLAB

More information

MATLAB: Quick Start Econ 837

MATLAB: Quick Start Econ 837 MATLAB: Quick Start Econ 837 Introduction MATLAB is a commercial Matrix Laboratory package which operates as an interactive programming environment. It is a programming language and a computing environment

More information

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 10 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Lecture 3 MATLAB programming (1) Dr.Qi Ying

Lecture 3 MATLAB programming (1) Dr.Qi Ying Lecture 3 MATLAB programming (1) Dr.Qi Ying Objectives Data types Logical operators/functions Branching Debugging of a program Data types in MATLAB Basic: Numeric (integer, floating-point, complex) Logical:

More information

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28 Control Structures Dr. Mihail March 1, 2015 (Dr. Mihail) Control March 1, 2015 1 / 28 Overview So far in this course, MATLAB programs consisted of a ordered sequence of mathematical operations, functions,

More information

function [s p] = sumprod (f, g)

function [s p] = sumprod (f, g) Outline of the Lecture Introduction to M-function programming Matlab Programming Example Relational operators Logical Operators Matlab Flow control structures Introduction to M-function programming M-files:

More information

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018 INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths July 2018 Outline MATLAB Scripts Relational Operations Program Control Statements Writing

More information

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD Introduction to MATLAB for Numerical Analysis and Mathematical Modeling Selis Önel, PhD Advantages over other programs Contains large number of functions that access numerical libraries (LINPACK, EISPACK)

More information

Mechanical Engineering Department Second Year

Mechanical Engineering Department Second Year Lecture 3: Control Statements if Statement It evaluates a logical expression and executes a group of statements when the expression is true. The optional (elseif) and else keywords provide for the execution

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs in MATLAB NOTE: For your

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

Programming in MATLAB

Programming in MATLAB 2. Scripts, Input/Output and if Faculty of mathematics, physics and informatics Comenius University in Bratislava October 7th, 2015 Scripts Scripts script is basically just a sequence of commands the same

More information

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

Programming 1. Script files. help cd Example:

Programming 1. Script files. help cd Example: Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands

More information

LECTURE 1. What Is Matlab? Matlab Windows. Help

LECTURE 1. What Is Matlab? Matlab Windows. Help LECTURE 1 What Is Matlab? Matlab ("MATrix LABoratory") is a software package (and accompanying programming language) that simplifies many operations in numerical methods, matrix manipulation/linear algebra,

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr A0B17MTB Matlab Part #1 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague You will learn Scalars, vectors, matrices (class

More information

A Quick Tutorial on MATLAB. Zeeshan Ali

A Quick Tutorial on MATLAB. Zeeshan Ali A Quick Tutorial on MATLAB Zeeshan Ali MATLAB MATLAB is a software package for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name

More information

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5. PIV Programming Last Class: 1. Introduction of μpiv 2. Considerations of Microscopy in μpiv 3. Depth of Correlation 4. Physics of Particles in Micro PIV 5. Measurement Errors 6. Special Processing Methods

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

Short Version of Matlab Manual

Short Version of Matlab Manual Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.

More information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems

ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems Disclaimer Problems seen in this study guide may resemble problems relating mainly to the pertinent homework assignments. Reading this

More information

An Introduction to MATLAB

An Introduction to MATLAB An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of

More information

Shell programming. Introduction to Operating Systems

Shell programming. Introduction to Operating Systems Shell programming Introduction to Operating Systems Environment variables Predened variables $* all parameters $# number of parameters $? result of last command $$ process identier $i parameter number

More information

ENGR 1181c Midterm Exam 2: Study Guide and Practice Problems

ENGR 1181c Midterm Exam 2: Study Guide and Practice Problems ENGR 1181c Midterm Exam 2: Study Guide and Practice Problems Disclaimer Problems seen in this study guide may resemble problems relating mainly to the pertinent homework assignments. Reading this study

More information

MATLAB. MATLAB Review. MATLAB Basics: Variables. MATLAB Basics: Variables. MATLAB Basics: Subarrays. MATLAB Basics: Subarrays

MATLAB. MATLAB Review. MATLAB Basics: Variables. MATLAB Basics: Variables. MATLAB Basics: Subarrays. MATLAB Basics: Subarrays MATLAB MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr MATLAB Basics Top-down Program Design, Relational and Logical Operators Branches and Loops

More information

A QUICK INTRODUCTION TO MATLAB

A QUICK INTRODUCTION TO MATLAB A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally

More information

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD Introduction to Computer Programming with MATLAB Matlab Fundamentals Selis Önel, PhD Today you will learn to create and execute simple programs in MATLAB the difference between constants, variables and

More information

Introduction to MATLAB

Introduction to MATLAB 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

More information

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Appendix A Glossary of Matlab Commands Mathematical Operations + Addition. Type help plus

More information

MATLAB Operators, control flow and scripting. Edited by Péter Vass

MATLAB Operators, control flow and scripting. Edited by Péter Vass MATLAB Operators, control flow and scripting Edited by Péter Vass Operators An operator is a symbol which is used for specifying some kind of operation to be executed. An operator is always the member

More information

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The

More information

Relational and Logical Operators

Relational and Logical Operators Relational and Logical Operators Relational Operators Relational operators are used to represent conditions (such as space 0 in the water tank example) Result of the condition is either true or false In

More information

Introduction to MATLAB

Introduction to MATLAB ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

More information

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered

More information

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up More on Scripts and Functions Basic Programming Lecture 2 Lecture 3 Lecture 4 Wrap Up Last time Loading data from file: load( filename ) Graphical input and

More information

ECE Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers

ECE Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers ECE 201 - Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers Script M-files : A script file is an external file that contains a sequence of MATLAB. By typing the filename, subsequent

More information

Functions of Two Variables

Functions of Two Variables Functions of Two Variables MATLAB allows us to work with functions of more than one variable With MATLAB 5 we can even move beyond the traditional M N matrix to matrices with an arbitrary number of dimensions

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced

More information

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing SECTION 5: STRUCTURED PROGRAMMING IN MATLAB ENGR 112 Introduction to Engineering Computing 2 Conditional Statements if statements if else statements Logical and relational operators switch case statements

More information

PREPARED FOR: ME 352: MACHINE DESIGN I Fall Semester School of Mechanical Engineering Purdue University West Lafayette, Indiana

PREPARED FOR: ME 352: MACHINE DESIGN I Fall Semester School of Mechanical Engineering Purdue University West Lafayette, Indiana INTRODUCTORY TUTORIAL TO MATLAB PREPARED FOR: ME 352: MACHINE DESIGN I Fall Semester 2017 School of Mechanical Engineering Purdue University West Lafayette, Indiana 47907-2088 August 21st, 2017 Table of

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

Scientific Computing with MATLAB

Scientific Computing with MATLAB Scientific Computing with MATLAB Dra. K.-Y. Daisy Fan Department of Computer Science Cornell University Ithaca, NY, USA UNAM IIM 2012 2 Focus on computing using MATLAB Computer Science Computational Science

More information

Programming in Mathematics. Mili I. Shah

Programming in Mathematics. Mili I. Shah Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window

More information

EE 216 Experiment 1. MATLAB Structure and Use

EE 216 Experiment 1. MATLAB Structure and Use EE216:Exp1-1 EE 216 Experiment 1 MATLAB Structure and Use This first laboratory experiment is an introduction to the use of MATLAB. The basic computer-user interfaces, data entry techniques, operations,

More information

CH6: Programming in MATLAB

CH6: Programming in MATLAB CH6: Programming in MATLAB 1- Relational and Logical operators: Relational operators: Examples Result >> 5>8 0 >> a= 6~=2 a=1 >> b= (3>2)+(5*2==10*1)*(32>=128/4) b=2 >> c= 8/(29) c=?? Order of

More information

MATLAB Second Seminar

MATLAB Second Seminar MATLAB Second Seminar Previous lesson Last lesson We learnt how to: Interact with MATLAB in the MATLAB command window by typing commands at the command prompt. Define and use variables. Plot graphs It

More information

Matlab Tutorial. CS Scientific Computation. Fall /51

Matlab Tutorial. CS Scientific Computation. Fall /51 Matlab Tutorial CS 370 - Scientific Computation Fall 2015 1/51 Outline Matlab Overview Useful Commands Matrix Construction and Flow Control Script/Function Files Basic Graphics 2/51 Getting to Matlab Everyone

More information

Lecture 1: Hello, MATLAB!

Lecture 1: Hello, MATLAB! Lecture 1: Hello, MATLAB! Math 98, Spring 2018 Math 98, Spring 2018 Lecture 1: Hello, MATLAB! 1 / 21 Syllabus Instructor: Eric Hallman Class Website: https://math.berkeley.edu/~ehallman/98-fa18/ Login:!cmfmath98

More information

CME 192: Introduction to Matlab

CME 192: Introduction to Matlab CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the

More information

Digital Image Analysis and Processing CPE

Digital Image Analysis and Processing CPE Digital Image Analysis and Processing CPE 0907544 Matlab Tutorial Dr. Iyad Jafar Outline Matlab Environment Matlab as Calculator Common Mathematical Functions Defining Vectors and Arrays Addressing Vectors

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003 Math 64 - Scientific Computing - Matlab Intro and Exercises: Spring 2003 Professor: L.G. de Pillis Time: TTh :5pm 2:30pm Location: Olin B43 February 3, 2003 Matlab Introduction On the Linux workstations,

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson A 30 Minute Introduction to Octave ENGR 390 - Engineering Mathematics Tony Richardson Introduction This is a brief introduction to Octave. It covers several topics related to both the statistics and linear

More information

Math 98 - Introduction to MATLAB Programming. Fall Lecture 1

Math 98 - Introduction to MATLAB Programming. Fall Lecture 1 Syllabus Instructor: Chris Policastro Class Website: https://math.berkeley.edu/~cpoli/math98/fall2016.html See website for 1 Class Number 2 Oce hours 3 Textbooks 4 Lecture schedule slides programs Syllabus

More information

Matlab Tutorial and Exercises for COMP61021

Matlab Tutorial and Exercises for COMP61021 Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

Getting To Know Matlab

Getting To Know Matlab Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better

More information

AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 4: Programming in Matlab Yasemin Bekiroglu (yaseminb@kth.se) Florian Pokorny(fpokorny@kth.se) Overview Overview Lecture 4: Programming in Matlab Wrap Up More on Scripts and Functions Wrap Up Last

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

Bourne Shell Reference

Bourne Shell Reference > Linux Reviews > Beginners: Learn Linux > Bourne Shell Reference Bourne Shell Reference found at Br. David Carlson, O.S.B. pages, cis.stvincent.edu/carlsond/cs330/unix/bshellref - Converted to txt2tags

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

EE 301 Signals & Systems I MATLAB Tutorial with Questions EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This

More information

CS335. Matlab Tutorial. CS335 - Computational Methods in Business and Finance. Fall 2016

CS335. Matlab Tutorial. CS335 - Computational Methods in Business and Finance. Fall 2016 Matlab Tutorial - Computational Methods in Business and Finance Fall 2016 1 / 51 Outline Matlab Overview Useful Commands Matrix Construction and Flow Control Script/Function Files Basic Graphics 2 / 51

More information

Introduction to MATLAB LAB 1

Introduction to MATLAB LAB 1 Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions

More information

Numerical Methods Lecture 1

Numerical Methods Lecture 1 Numerical Methods Lecture 1 Basics of MATLAB by Pavel Ludvík The recommended textbook: Numerical Methods Lecture 1 by Pavel Ludvík 2 / 30 The recommended textbook: Title: Numerical methods with worked

More information

Files and File Management Scripts Logical Operations Conditional Statements

Files and File Management Scripts Logical Operations Conditional Statements Files and File Management Scripts Logical Operations Conditional Statements Files and File Management Matlab provides a group of commands to manage user files pwd: Print working directory displays the

More information

MBI REU Matlab Tutorial

MBI REU Matlab Tutorial MBI REU Matlab Tutorial Lecturer: Reginald L. McGee II, Ph.D. June 8, 2017 MATLAB MATrix LABoratory MATLAB is a tool for numerical computation and visualization which allows Real & Complex Arithmetics

More information