Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics. MathScript

Size: px
Start display at page:

Download "Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics. MathScript"

Transcription

1 Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Solutions So You Think You Can HANS-PETTER HALVORSEN, MathScript Part I: Introduction to MathScript Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: Fax:

2 Table of Contents Table of Contents...ii 1 Introduction to MathScript Matrices and Vectors Solving Linear Equations Plotting Functions Calling functions in MathScript User-Defined Functions in MathScript Scripts Flow Control Additional Tasks ii

3 1 Introduction to MathScript Task 1: Math function Given the following function: ( ) Find ( ) and ( ) We find ( ): In order to do that, we type the following in the Command Window: First we need to define x: x=2 Then we can define the function: y = (4*x + 2)/x Then MathScript respond with the following answer: y = 5 We find ( ): We define a new value for x: x=5 Then we execute the function once more: y = (4*x + 2)/x 3

4 4 Introduction to MathScript Then MathScript respond with the following answer: y = 4.4 Task 2: Math function Create the following mathematical expression in MathScript: ( ) is a function of and, i.e. ( ). Use MathScript to find ( ). Tip! Use the following built-in functionality: x^2 sqrt(x) ( ) log(x) exp(x) MathScript code: x=2; y=2; z=3*x^2 + sqrt(x^2+y^2)+exp(log(x)); 1.1 Matrices and Vectors Task 3: Vectors and Matrices Type the following vector in MathScript in the Command window: [ ]

5 5 Introduction to MathScript Type the following matrix in MathScript in the Command window: * + Type the following matrix in MathScript in the Command window: [ ] MathScript Code: x=[1 2 3] A=[0 1; -2-3] C=[-1 2 0; ; 1 0 6] Use Use MathScript to find the value in the second row and the third column of matrix C. C(2,3) This gives: ans = -2 Use MathScript to find the second row of matrix C. C(2,:) This gives: ans = Use MathScript to find the third column of matrix C. C(:,3) This gives:

6 6 Introduction to MathScript ans = Task 4: Linear Algebra (You may want to skip this task if you haven t learned about Linear Algebra yet) Given the matrix A, B and C: * + * + * + Solve the following basic matrix operations using MathScript: ( ) ( ) ( ) ( ) ( ) ( ) where eig = Eigenvalues, diag = Diagonal, det = Determinant A=[0 1;-2-3] B=[1 0; 3-2] C=[1-1; -2 2] A+B A-B A' inv(a) diag(a) diag(b) det(a) det(b) det(a*b) eig(a)

7 7 Introduction to MathScript Task 5: Matrices (You may want to skip this task if you haven t learned about Linear Algebra yet) Use MathScript to prove the following: ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) where is the unit matrix Since we haven t learned about if yet, you can simple do like this: A*B This gives the following answer: ans =

8 8 Introduction to MathScript B*A This gives the following answer: ans = We see that the answers is not the same, and therefore 1.2 Solving Linear Equations Task 6: Equations (You may want to skip this task if you haven t learned about Linear Algebra yet) Given the equations: Set the equations on the following form: Find A and b. Solve the equations, i.e., find, using MathScript. A=[1 2; 3 4] b=[5;6] x=inv(a)*b The solution is displayed in the Output window:

9 9 Introduction to MathScript

10 2 Plotting Task 7: Plotting In the Command window in MathScript window input the time from t=0 seconds to t=10 seconds in increments of 0.1 seconds as follows: >>t=[0:0.1:10]; Then, compute the output y as follows: >>y=cos(t); Use the Plot command: >>plot(t,y) Task 8: Plotting Plot ( ) and ( ) for in the same plot. Make sure to add labels and a legend, and use different line styles and colors for the plots. Note! We cannot use Greek letters in MathScript, but use, e.g., theta, x or another name for your variable. Using the hold on command: The code becomes: x=0:0.01:2*pi; clf plot(x, sin(x), 'c+:') hold on 10

11 11 Plotting plot(x, cos(x), 'r:') hold off legend('sin', 'cos') xlabel('x') ylabel('f(x)') The plot becomes: You may also use the plot command like this instead of using the hold on command: plot(x, sin(x), x, cos(x)) For line colors and line-styles we have the following properties we can use for the plot function: Line Styles:

12 12 Plotting Marker specifiers: Colors:

13 13 Plotting Task 9: Plot of dynamic system Given the following differential equation: where,where is the time constant The solution for the differential equation is: ( ) Set and the initial condition ( ) Plot the solution ( ) in the time interval Add Grid, and proper Title and Axis Labels to the plot. We define a script (m-file): %Define Variabes T=5; a=-1/t; %Start Condition, etc

14 14 Plotting x0=1; t=[0:1:25] %Define the function x=exp(a*t)*x0; %Plotting plot(t,x); grid title('simulation of x'' = ax') xlabel('time') ylabel('x') The result becomes: Task 10: Sub-plots Plot Sin(x) and Cos(x) in 2 different subplots. Add Titles and Labels. We define a script: % Define x-values

15 15 Plotting x=0:0.01:2*pi; % subplot 1 subplot(2,1,1) plot(x, sin(x)) title('plotting sin(x)') xlabel('x') ylabel('sin(x)') % Subplot 2 subplot(2,1,2) plot(x, cos(x)) title('plotting cos(x)') xlabel('x') ylabel('cos(x)') This gives the following plot:

16 3 Functions 3.1 Calling functions in MathScript Task 11: Statistics Given the vector: >>x=[ ] Find the mean value of the vector x. Find the minimum value of the vector x. Find the maximum value of the vector x. x=[ ] mean(x) min(x) max(x) 3.2 User-Defined Functions in MathScript Task 12: User-defined function Create a function calc_average that finds the average of two numbers. Test the function afterwards as follows: >>x=2; >>y=4; >>z=calc_average(x,y) 16

17 17 Functions Make sure to enter search path for the function: The function becomes: 3.3 Scripts Task 13: Script Create a new Script where you use the function you created in the previous task. Call it several times with different inputs.

18 18 Functions Task 14: Conversion It is quite easy to convert from radians to degrees or from degrees to radians. We have that: This gives: [ ] [ ] [ ] [ ] ( ) [ ] [ ] ( ) Create two functions that convert from radians to degrees (r2d(x)) and from degrees to radians (d2r(x)) respectively. Test the functions to make sure that they work as expected. The functions are as follows: function d = r2d(r) d=r*180/pi; and function r = d2r(d) r=d*pi/180; Testing the functions: >> r2d(2*pi) ans = 360 >> d2r(180) ans = Or: x = 0:0.1:360; x2 = d2r(x) y = sin(x2) plot(x,y)

19 19 Functions From the tests, we see the functions are correct.

20 4 Flow Control Task 15: For Loop Extend your calc_average function from a previous task so it can calculate the average of a vector with random elements. Use a For loop to iterate through the values in the vector and find sum in each iteration, e.g.: mysum = mysum + x(i); Test the function in the Command window Function: function av = calc_average2(x) %This function calculates the average of a vector x N=length(x); tot=0; for i=1:n tot=tot+x(i); end av=tot; Calling the function: x=rand(100) calc_average2(x) Task 16: If-else Depending on a variable a, different functions should be executed and plotted. ( ) ( ) ( ) Create a script that plot based on the value of the input. 20

21 21 Flow Control Code: clear clc a=1; %Try with different values here! x = 0:0.1:2*pi; if a == 1 y=sin(x) elseif a == 2; y=cos(x) elseif a == 3 y=tan(x); else y=x; end plot(x,y) Task 17: Fibonacci Numbers In mathematics, Fibonacci numbers are the numbers in the following sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, By definition, the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s. In mathematical terms, the sequence of Fibonacci numbers is defined by the recurrence relation: with seed values: Write a function in MathScript that calculates the N first Fibonacci numbers, e.g., >> N=10; >> fibonacci(n) ans =

22 22 Flow Control Use a For loop to solve the problem. Fibonacci numbers are used in the analysis of financial markets, in strategies such as Fibonacci retracement, and are used in computer algorithms such as the Fibonacci search technique and the Fibonacci heap data structure. They also appear in biological settings, such as branching in trees, arrangement of leaves on a stem, the fruitlets of a pineapple, the flowering of artichoke, an uncurling fern and the arrangement of a pine cone. function f = fibonacci(n) f=zeros(n,1); f(1)=0; f(2)=1; for k=3:n f(k)=f(k-1)+f(k-2); end

23 5 Additional Tasks Task 18: If-else Given the second order algebraic equation: The solution (roots) is as follows: where - there is no solution, - any complex number is a solution { Create a function that finds the solution for based on different input values for a, b and c, e.g., function x = solveeq(a,b,c) Use if-else statements to solve the problems Test the function from the Command window to make sure it works as expected, e.g., >> a=0, b=2, c=1 >> solveeq(a,b,c) You may define the function like this: function x = solveeq(a,b,c) if a~=0 x = zeros(2,1); x(1,1)=(-b+sqrt(b^2-4*a*c))/(2*a); x(2,1)=(-b-sqrt(b^2-4*a*c))/(2*a); elseif b~=0 23

24 24 Additional Tasks x=-c/b; elseif c~=0 disp('no solution') else disp('any complex number is a solution') end We test the function: >> a=0, b=2,c=1 a = 0 b = 2 c = 1 >> solveeq(a,b,c) ans = Or: >> a=1;, b=2;,c=1; >> solveeq(a,b,c) ans = -1 0 Or: >> a=0;, b=0;,c=1; >> solveeq(a,b,c) No solution Or: >> a=0;, b=0;,c=0; >> solveeq(a,b,c) Any complex number is a solution Task 19: Basic Math function Create a function that calculates the following mathematical expression: ( )

25 25 Additional Tasks The function becomes: function z=calcexpression(x,y) z=3*x^2 + sqrt(x^2+y^2)+exp(log(x)); Testing the function gives: >> x=2; y=2; >> calcexpression(x,y) ans = Task 20: User-defined function Create a function that uses Pythagoras to calculate the hypotenuse of a right-angled triangle, e.g.: function h = pyt(a,b) %.. h = Pythagoras theorem is as follows: Note! The function should handle that a and b could be vectors. The function may be written like this: function h = pyt(a,b) % This function calculates the hypotenuse of a right-angled triangle h=sqrt(a^2 + b^2);

26 26 Additional Tasks Testing the function in the Command window gives: >> pyt(2,3) ans = What if a and b are vectors? Let s try: >> a=rand(10,1)*10; >> b=rand(10,1)*10; >> pyt(a,b)??? Error using ==> mpower Matrix must be square. Error in ==> pyt at 4 h=sqrt(a^2 + b^2); As you see this gives an error. Let s modify our function so it possible for a and b to be vectors: function h = pyt(a,b) % This function calculates the hypotenuse of a right-angled triangle h=sqrt(a.^2 + b.^2); Testing the function gives: >> a=rand(10,1)*10; >> b=rand(10,1)*10; >> pyt(a,b) ans = As you see it now works with arrays to, thanks to a.^2 and b.^2. Task 21: Cylinder surface area Create a function that finds the surface area of a cylinder based on the height (h) and the radius (r) of the cylinder.

27 27 Additional Tasks We do like this: The function becomes: function A = cylindar_surface(h,r) % This function calculates the surface of a sylindar A = 2*pi*r^2 +2*pi*r*h; Testing the function: >> h=8 h = 8 >> r=3 r = 3 >> cylindar_surface(h,r) ans =

28 28 Additional Tasks Task 22: Create advanced expressions in MathScript Create the following expression in MathScript: ( ) ( ) ( ) ( )( ) Given Find ( ) (The answer should be ( ) ) Tip! You should split the expressions into different parts, such as: poly = num = den =. f = This makes the expression simpler to read and understand, and you minimize the risk of making an error while typing the expression in MathScript. The Script (advexpression.m) becomes: % Define the variables: a = 1; b = 3; c = 5; x = 9; % Split functions into parts for easy maintenance poly = a*x^2 + b*x + c; num = log(poly)-sin(poly); den = 4*pi*x^2 +cos(x-2)*poly; f = num/den Testing the Script: >> advexpression f =

29 29 Additional Tasks Task 23: Solving Equations Find the solution(s) for the given equations: Set the equations on the following form: The solution is: Lets find A and b: [ ] [ ] Code: >> A=[1 2; 3 4; 7 8] A = >> b=[5;6;9] b = >> x=inv(a)*b??? Error using ==> inv Matrix must be square. We get an error (as expected!) because A must be square in order to find the inverse of A. In this case we have to do the following: >> x=a\b

30 30 Additional Tasks x = Task 24: Script Given the famous equation from Albert Einstein: The sun radiates of energy per day. Calculate how much of the mass on the sun is used to create this energy per day. How many years will it take to convert all the mass of the sun completely? Do we need to worry if the sun will be used up in our generation or the next? The mass of the sun is The speed of light is: The mass on the sun is needed to create this energy per day: where: Energy per day is: This gives: Where ( )

31 31 Additional Tasks This gives: Times to it takes to convert all the mass of the sun completely: This gives: The script becomes as follows: clc %Define variables c = 3e8; %[m/s] E = 385e24; %[J/s] %Need to convert: E = E*60*60*24; %[J] %Mass of the sun used to create this amount of energy m = E/c^2 %[kg] %Total mass of sun: m_sun = 2e30; %[kg] %Number of days before sun is gone days = m_sun/m; %[days] %Number of years before sun is gone years = days/365 %[years] The Answers is: m = e+014 years = e+013 The mass on the sun is needed to create this energy per day:

32 32 Additional Tasks Numbers of years it will take to convert all the mass of the sun completely:

33 Telemark University College Faculty of Technology Kjølnes Ring 56 N-3914 Porsgrunn, Norway Hans-Petter Halvorsen, M.Sc. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Phone: Blog: Room: B-237a

LabVIEW MathScript Quick Reference

LabVIEW MathScript Quick Reference Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LabVIEW MathScript Quick Reference Hans-Petter Halvorsen, 2012.06.14 Faculty of Technology, Postboks

More information

MATLAB Examples. Flow Control and Loops. Hans-Petter Halvorsen, M.Sc.

MATLAB Examples. Flow Control and Loops. Hans-Petter Halvorsen, M.Sc. MATLAB Examples Flow Control and Loops Hans-Petter Halvorsen, M.Sc. Flow Control and Loops in MATLAB Flow Control: if-elseif-else statement switch-case-otherwise statement Loops: for Loop while Loop The

More information

Introduction to MATLAB

Introduction to MATLAB Quick Start Tutorial Introduction to MATLAB Hans-Petter Halvorsen, M.Sc. What is MATLAB? MATLAB is a tool for technical computing, computation and visualization in an integrated environment. MATLAB is

More information

Solutions. Discretization HANS-PETTER HALVORSEN,

Solutions. Discretization HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Solutions HANS-PETTER HALVORSEN, 2011.08.12 Discretization Faculty of Technology, Postboks 203,

More information

State Estimation with Observers

State Estimation with Observers Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics State Estimation with Observers HANS-PETTER HALVORSEN, 2012.08.20 Faculty of Technology, Postboks

More information

Virtual Instruments with LabVIEW

Virtual Instruments with LabVIEW Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Virtual Instruments with LabVIEW HANS-PETTER HALVORSEN, 2011.01.04 Faculty of Technology, Postboks

More information

Control and Simulation in. LabVIEW

Control and Simulation in. LabVIEW Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Solutions Control and Simulation in HANS-PETTER HALVORSEN, 2011.08.11 LabVIEW Faculty of Technology,

More information

Linear Algebra in LabVIEW

Linear Algebra in LabVIEW https://www.halvorsen.blog Linear Algebra in LabVIEW Hans-Petter Halvorsen, 2018-04-24 Preface This document explains the basic concepts of Linear Algebra and how you may use LabVIEW for calculation of

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

Wireless DAQ using ZigBee

Wireless DAQ using ZigBee Høgskolen i Telemark Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Wireless DAQ using ZigBee Cuong Nguyen, Hans- Petter Halvorsen 2013.10.29 Hardware

More information

NI Vision System HANS- PETTER HALVORSEN,

NI Vision System HANS- PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics NI Vision System HANS- PETTER HALVORSEN, 2013.02.19 Faculty of Technology, Postboks 203, Kjølnes

More information

Computer Programming in MATLAB

Computer Programming in MATLAB Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Engineering Faculty Department of Mechanical Engineering Arrays in MATLAB; Vectors and Matrices Graphing Vector Generation Before graphing plots in

More information

NI mydaq HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

NI mydaq HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics NI mydaq HANS-PETTER HALVORSEN, 2012.01.20 Faculty of Technology, Postboks 203, Kjølnes ring 56,

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

Introduction to Matlab

Introduction to Matlab NDSU Introduction to Matlab pg 1 Becoming familiar with MATLAB The console The editor The graphics windows The help menu Saving your data (diary) Solving N equations with N unknowns Least Squares Curve

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

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Introduction to PartSim and Matlab

Introduction to PartSim and Matlab NDSU Introduction to PartSim and Matlab pg 1 PartSim: www.partsim.com Introduction to PartSim and Matlab PartSim is a free on-line circuit simulator that we use in Circuits and Electronics. It works fairly

More information

Data Acquisition HANS-PETTER HALVORSEN,

Data Acquisition HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Data Acquisition HANS-PETTER HALVORSEN, 2011.10.14 Faculty of Technology, Postboks 203, Kjølnes

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

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

Datalogging in LabVIEW

Datalogging in LabVIEW Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Datalogging in LabVIEW HANS-PETTER HALVORSEN, 2011.01.04 Faculty of Technology, Postboks 203, Kjølnes

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

LABVIEW MATHSCRIPT HANS-PETTER HALVORSEN,

LABVIEW MATHSCRIPT HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LABVIEW MATHSCRIPT HANS-PETTER HALVORSEN, 2010.05.25 Faculty of Technology, Postboks 203, Kjølnes

More information

2.2 Creating & Initializing Variables in MATLAB

2.2 Creating & Initializing Variables in MATLAB 2.2 Creating & Initializing Variables in MATLAB Slide 5 of 27 Do-It-Yourself (DIY) EXERCISE 2-1 Answer the followings: (a) What is the difference between an array, a matrix, and a vector? (b) Let: c =

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

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 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

Introduction To MATLAB Introduction to Programming GENG 200

Introduction To MATLAB Introduction to Programming GENG 200 Introduction To MATLAB Introduction to Programming GENG 200, Prepared by Ali Abu Odeh 1 Table of Contents M Files 2 4 2 Execution Control 3 Vectors User Defined Functions Expected Chapter Duration: 6 classes.

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

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms: Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

More information

MATLAB Examples. Interpolation and Curve Fitting. Hans-Petter Halvorsen

MATLAB Examples. Interpolation and Curve Fitting. Hans-Petter Halvorsen MATLAB Examples Interpolation and Curve Fitting Hans-Petter Halvorsen Interpolation Interpolation is used to estimate data points between two known points. The most common interpolation technique is Linear

More information

Basic MATLAB Tutorial

Basic MATLAB Tutorial Basic MATLAB Tutorial http://www1gantepedutr/~bingul/ep375 http://wwwmathworkscom/products/matlab This is a basic tutorial for the Matlab program which is a high-performance language for technical computing

More information

Matlab and Octave: Quick Introduction and Examples 1 Basics

Matlab and Octave: Quick Introduction and Examples 1 Basics Matlab and Octave: Quick Introduction and Examples 1 Basics 1.1 Syntax and m-files There is a shell where commands can be written in. All commands must either be built-in commands, functions, names of

More information

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

More information

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab Overview Lecture 13: Graphics and Visualisation Graphics & Visualisation 2D plotting 1. Plots for one or multiple sets of data, logarithmic scale plots 2. Axis control & Annotation 3. Other forms of 2D

More information

MATLAB Guide to Fibonacci Numbers

MATLAB Guide to Fibonacci Numbers MATLAB Guide to Fibonacci Numbers and the Golden Ratio A Simplified Approach Peter I. Kattan Petra Books www.petrabooks.com Peter I. Kattan, PhD Correspondence about this book may be sent to the author

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

Lab #1 Revision to MATLAB

Lab #1 Revision to MATLAB Lab #1 Revision to MATLAB Objectives In this lab we would have a revision to MATLAB, especially the basic commands you have dealt with in analog control. 1. What Is MATLAB? MATLAB is a high-performance

More information

Table of Contents. Basis CEMTool 7 Tutorial

Table of Contents. Basis CEMTool 7 Tutorial PREFACE CEMTool (Computer-aided Engineering & Mathematics Tool) is a useful computational tool in science and engineering. No matter what you background be it physics, chemistry, math, or engineering it

More information

To see what directory your work is stored in, and the directory in which Matlab will look for files, type

To see what directory your work is stored in, and the directory in which Matlab will look for files, type Matlab Tutorial For Machine Dynamics, here s what you ll need to do: 1. Solve n equations in n unknowns (as in analytical velocity and acceleration calculations) - in Matlab, this is done using matrix

More information

Mechanical Engineering Department Second Year (2015)

Mechanical Engineering Department Second Year (2015) Lecture 7: Graphs Basic Plotting MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. This section describes a few of the most

More information

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

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

Introduction to MATLAB

Introduction to MATLAB GENG 200 Introduction to Programming Faculty of Engineering, ERU Table of Contents 1. Getting Started with MATLAB... 3 1.1 Introduction... 3 1.2 Graphical User Interface... 3 1.3 Help Menu... 4 1.4 Basic

More information

DAQ in MATLAB HANS-PETTER HALVORSEN,

DAQ in MATLAB HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics DAQ in MATLAB HANS-PETTER HALVORSEN, 2011.06.07 Faculty of Technology, Postboks 203, Kjølnes ring

More information

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

What is log a a equal to?

What is log a a equal to? How would you differentiate a function like y = sin ax? What is log a a equal to? How do you prove three 3-D points are collinear? What is the general equation of a straight line passing through (a,b)

More information

MATLAB Examples. Simulink. Hans-Petter Halvorsen, M.Sc.

MATLAB Examples. Simulink. Hans-Petter Halvorsen, M.Sc. MATLAB Examples Simulink Hans-Petter Halvorsen, M.Sc. What is Simulink? Simulink is an add-on to MATLAB. You need to have MATLAB in order to use Simulink Simulink is used for Simulation of dynamic models

More information

PERI INSTITUTE OF TECHNOLOGY DEPARTMENT OF ECE TWO DAYS NATIONAL LEVEL WORKSHOP ON COMMUNICATIONS & IMAGE PROCESSING "CIPM 2017" Matlab Fun - 2

PERI INSTITUTE OF TECHNOLOGY DEPARTMENT OF ECE TWO DAYS NATIONAL LEVEL WORKSHOP ON COMMUNICATIONS & IMAGE PROCESSING CIPM 2017 Matlab Fun - 2 Table of Contents PERI INSTITUTE OF TECHNOLOGY DEPARTMENT OF ECE TWO DAYS NATIONAL LEVEL WORKSHOP ON COMMUNICATIONS & IMAGE PROCESSING "CIPM 2017" - 2 What? Matlab can be fun... 1 Plot the Sine Function...

More information

11/30/15 11:09 AM C:\websi...\mathcad_homework_in_Matlab.m 1 of 6

11/30/15 11:09 AM C:\websi...\mathcad_homework_in_Matlab.m 1 of 6 11/30/15 11:09 AM C:\websi...\mathcad_homework_in_Matlab.m 1 of 6 %% mathcad_homework_in_matlab.m Dr. Dave S# %% Basic calculations - solution to quadratic equation: a*x^2 + b*x + c = 0 clc % clear the

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Kristian Sandberg Department of Applied Mathematics University of Colorado Goal The goal with this worksheet is to give a brief introduction to the mathematical software Matlab.

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

Fall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB

Fall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB Fall 2014 MAT 375 Numerical Methods Introduction to Programming using MATLAB Some useful links 1 The MOST useful link: www.google.com 2 MathWorks Webcite: www.mathworks.com/help/matlab/ 3 Wikibooks on

More information

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

More information

MATLAB BEGINNER S GUIDE

MATLAB BEGINNER S GUIDE MATLAB BEGINNER S GUIDE About MATLAB MATLAB is an interactive software which has been used recently in various areas of engineering and scientific applications. It is not a computer language in the normal

More information

mathcad_homework_in_matlab.m Dr. Dave S#

mathcad_homework_in_matlab.m Dr. Dave S# Table of Contents Basic calculations - solution to quadratic equation: a*x^ + b*x + c = 0... 1 Plotting a function with automated ranges and number of points... Plotting a function using a vector of values,

More information

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. PC-MATLAB PRIMER This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. >> 2*3 ans = 6 PCMATLAB uses several lines for the answer, but I ve edited this to save space.

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

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

Exercise 11: Discretization

Exercise 11: Discretization Exercise 11: Discretization Introduction We will use different discretization methods using pen and paper exercises and in practical implementation in MathScript/LabVIEW along with built-in discretization

More information

Faculty of Technology, Department of Electrical Engineering, Information Technology and Cybernetics. SCADA System

Faculty of Technology, Department of Electrical Engineering, Information Technology and Cybernetics. SCADA System Høgskolen i Telemark Telemark University College Faculty of Technology, Department of Electrical Engineering, Information Technology and Cybernetics SCADA System Keywords: Data Communication, protocols,

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab The purpose of this intro is to show some of Matlab s basic capabilities. Nir Gavish, 2.07 Contents Getting help Matlab development enviroment Variable definitions Mathematical operations

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

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization Teaching Assistant: Pei-Yuan Zhou Contact: cspyzhou@comp.polyu.edu.hk Lab 2: 19 Sep., 2014 1 Review Find the Matlab under the folder

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

Chapter 2. MathScript

Chapter 2. MathScript Chapter 2. MathScript 2.1 What is MathScript MathScript is math-oriented, text-based computing language to address tasks mathematic calculation: Most suitable for Mathematic calculation. Matrix based data

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Enrique Muñoz Ballester Dipartimento di Informatica via Bramante 65, 26013 Crema (CR), Italy enrique.munoz@unimi.it Contact Email: enrique.munoz@unimi.it Office: Room BT-43 Industrial,

More information

Matlab 1: Get Started

Matlab 1: Get Started Matlab 1: Get Started 1 Starting/Existing Matlab 2/2 Run matlab in command line: In Terminal/console i.change to you work directory ii.type: matlab -nodesktop iii.to close it, type exit 3 Keep track of

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

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

To start using Matlab, you only need be concerned with the command window for now.

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

Introduction to MATLAB

Introduction to MATLAB CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical

More information

Due date for the report is 23 May 2007

Due date for the report is 23 May 2007 Objectives: Learn some basic Matlab commands which help you get comfortable with Matlab.. Learn to use most important command in Matlab: help, lookfor. Data entry in Microsoft excel. 3. Import data into

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

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

What is Matlab? A software environment for interactive numerical computations

What is Matlab? A software environment for interactive numerical computations What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS

MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS This tutorial is essential pre-requisite material for anyone studying mechanical engineering. This tutorial uses the principle of learning by example.

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. A Tutorial By. Masood Ejaz

MATLAB. A Tutorial By. Masood Ejaz MATLAB A Tutorial By Masood Ejaz Note: This tutorial is a work in progress and written specially for CET 3464 Software Programming in Engineering Technology, a course offered as part of BSECET program

More information

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command... Contents 2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command... 9 2D LINE PLOTS One of the benefits of programming in MATLAB

More information

Introduction to Unix and Matlab

Introduction to Unix and Matlab Introduction to Unix and Matlab 1 Introduction to the Unix System 1.1 Login Pick any machine in Room 451; the screen is probably dark. If so, press the [return] key once or twice. You should see something

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

Matlab Tutorial 1: Working with variables, arrays, and plotting

Matlab Tutorial 1: Working with variables, arrays, and plotting Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.

More information

Topic 3. Mathematical Operations Matrix & Linear Algebra Operations Element-by-Element(array) Operations

Topic 3. Mathematical Operations Matrix & Linear Algebra Operations Element-by-Element(array) Operations Topic 3 Mathematical Operations Matrix & Linear Algebra Operations Element-by-Element(array) Operations 1 Introduction Matlab is designed to carry out advanced array operations that have many applications

More information

Høgskolen i Telemark Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics.

Høgskolen i Telemark Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics. Høgskolen i Telemark Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Wi- Fi DAQ Hardware Setup Cuong Nguyen, Hans- Petter Halvorsen, 2013.08.07

More information

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs...

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs... Introduction to Plotting with Matlab Math Sciences Computing Center University ofwashington September, 1996 Contents Fundamentals........................................... 1 Making Plots...........................................

More information

.(3, 2) Co-ordinate Geometry Co-ordinates. Every point has two co-ordinates. Plot the following points on the plane. A (4, 1) D (2, 5) G (6, 3)

.(3, 2) Co-ordinate Geometry Co-ordinates. Every point has two co-ordinates. Plot the following points on the plane. A (4, 1) D (2, 5) G (6, 3) Co-ordinate Geometry Co-ordinates Every point has two co-ordinates. (3, 2) x co-ordinate y co-ordinate Plot the following points on the plane..(3, 2) A (4, 1) D (2, 5) G (6, 3) B (3, 3) E ( 4, 4) H (6,

More information

Computational Foundations of Cognitive Science. Inverse. Inverse. Inverse Determinant

Computational Foundations of Cognitive Science. Inverse. Inverse. Inverse Determinant Computational Foundations of Cognitive Science Lecture 14: s and in Matlab; Plotting and Graphics Frank Keller School of Informatics University of Edinburgh keller@inf.ed.ac.uk February 23, 21 1 2 3 Reading:

More information

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services MATLAB INTRODUCTION Risk analysis lab 2018 2018. szeptember 10., Budapest Ceffer Attila PhD student BUTE Department Of Networked Systems and Services ceffer@hit.bme.hu Előadó képe MATLAB Introduction 2

More information

Lecture 1: Introduction to Scilab

Lecture 1: Introduction to Scilab Lecture 1: Introduction to Scilab Ahmed Kebaier kebaier@math.univ-paris13.fr HEC, Paris Outline 1 First Steps with Scilab 2 Outline 1 First Steps with Scilab 2 After launching Scilab, you can test the

More information

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to. Starting Matlab Go to MATLAB Laboratory 09/09/10 Lecture Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu http://ctx.loyola.edu and login with your Loyola name and password...

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

PROGRAMMING WITH MATLAB WEEK 6

PROGRAMMING WITH MATLAB WEEK 6 PROGRAMMING WITH MATLAB WEEK 6 Plot: Syntax: plot(x, y, r.- ) Color Marker Linestyle The line color, marker style and line style can be changed by adding a string argument. to select and delete lines

More information

An Introduction to MATLAB II

An Introduction to MATLAB II Lab of COMP 319 An Introduction to MATLAB II Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 2: 16th Sep, 2013 1 Outline of Lab 2 Review of Lab 1 Matrix in Matlab

More information