LabVIEW MathScript Quick Reference

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

Introduction to MATLAB

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

Solutions. Discretization HANS-PETTER HALVORSEN,

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

Virtual Instruments with LabVIEW

State Estimation with Observers

Introduction to Matlab

Introduction to MATLAB

PART 1 PROGRAMMING WITH MATHLAB

Programming in Mathematics. Mili I. Shah

Data Acquisition HANS-PETTER HALVORSEN,

Wireless DAQ using ZigBee

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

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

Control and Simulation in. LabVIEW

NI Vision System HANS- PETTER HALVORSEN,

Getting Started with MATLAB

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

Lecturer: Keyvan Dehmamy

MATLAB and Numerical Analysis

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

Linear Algebra in LabVIEW

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MATLAB LAB 1

Datalogging in LabVIEW

MATLAB BEGINNER S GUIDE

Introduction to MATLAB

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

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

Desktop Command window

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Basic MATLAB Tutorial

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017

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

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

What is Matlab? The command line Variables Operators Functions

INTRODUCTION TO MATLAB

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Introduction to Engineering gii

Introduction to MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

A Quick Tutorial on MATLAB. Zeeshan Ali

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

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

DAQ in MATLAB HANS-PETTER HALVORSEN,

LABVIEW MATHSCRIPT HANS-PETTER HALVORSEN,

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Lecture 2: Variables, Vectors and Matrices in MATLAB

Introduction To MATLAB Introduction to Programming GENG 200

MATLAB. A Tutorial By. Masood Ejaz

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

MATLAB: Quick Start Econ 837

Some elements for Matlab programming

Basic Graphs. Dmitry Adamskiy 16 November 2011

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

MATLAB GUIDE UMD PHYS401 SPRING 2011

What is Matlab? A software environment for interactive numerical computations

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Chapter 1 Introduction to MATLAB

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

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Chapter 2. MATLAB Fundamentals

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

Exercise 11: Discretization

Getting started with MATLAB

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

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

MATLAB Functions and Graphics

Due date for the report is 23 May 2007

Modeling and Simulating Social Systems with MATLAB

Fundamentals of MATLAB Usage

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

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

Getting Started with Matlab

Wireless DAQ System. In this project you are going to create a Wireless DAQ System, see Figure 1-1. Figure 1-1: Wireless DAQ system

Introduction to Matlab

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

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

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

AMS 27L LAB #2 Winter 2009

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Introduction to MATLAB

A Brief MATLAB Tutorial

Finding, Starting and Using Matlab

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

MATLAB TUTORIAL WORKSHEET

QUICK INTRODUCTION TO MATLAB PART I

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Chapter 1 MATLAB Preliminaries

Introduction to PartSim and Matlab

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

MATLAB Introductory Course Computer Exercise Session

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

Image Processing CS 6640 : An Introduction to MATLAB Basics Bo Wang and Avantika Vardhan

MATLAB Project: Getting Started with MATLAB

Transcription:

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 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01

LabVIEW MathScript Quick Reference 2/16 Introduction MathScript is a high-level, text- based programming language. MathScript includes more than 800 built-in functions and the syntax is similar to MATLAB. You may also create custom-made m-file like you do in MATLAB. MathScript is an add-on module to LabVIEW but you don t need to know LabVIEW programming in order to use MathScript. How do you start using MathScript? You need to install LabVIEW and the LabVIEW MathScript RT Module. When necessary software is installed, start MathScript by open LabVIEW: In the Getting Started window, select Tools -> MathScript Window...:

LabVIEW MathScript Quick Reference 3/16 You can use the LabVIEW MathScript Window to enter commands one at time (Command Window). You also can enter batch scripts in a simple text editor window (Script Window), loaded from a text file, or imported from a separate text editor. Below we see the LabVIEW MathScript window:

LabVIEW MathScript Quick Reference 4/16 Basic Operations Basic Functions Here are some descriptions for the most used basic MathScript functions. Function Description Example help help <function> who, whos MathScript displays the help information available Display help about a specific function who lists in alphabetical order all variables in the currently active workspace. >>help >>help plot >>who >>whos clear Clear variables and functions from memory. >>clear >>clear x size Size of arrays, matrices >>x=[1 2 ; 3 4]; >>size(a) length Length of a vector >>x=[1:1:10]; >>length(x) format Set output format disp Display text or array >>A=[1 2;3 4]; >>disp(a) plot This function is used to create a plot >>x=[1:1:10]; >>plot(x) clc Clear the Command window >>cls >>y=sin(x); >>plot(x,y) rand Creates a random number, vector or matrix >>rand >>rand(2,1) max Find the largest number in a vector >>x=[1:1:10] >>max(x) min Find the smallest number in a vector >>x=[1:1:10] >>min(x) mean Average or mean value >>x=[1:1:10] >>mean(x) std Standard deviation >>x=[1:1:10] >>std(x)

LabVIEW MathScript Quick Reference 5/16 Linear Algebra Here are some useful functions for Linear Algebra in MathScript: Function Description Example rank Find the rank of a matrix. Provides an estimate of the number of linearly independent rows or columns of a matrix A. >>A=[1 2; 3 4] >>rank(a) det Find the determinant of a square matrix >>A=[1 2; 3 4] >>det(a) inv Find the inverse of a square matrix >>A=[1 2; 3 4] >>inv(a) eig Find the eigenvalues of a square matrix >>A=[1 2; 3 4] >>eig(a) ones Creates an array or matrix with only ones >>ones(2) >>ones(2,1) eye Creates an identity matrix >>eye(2) diag Find the diagonal elements in a matrix >>A=[1 2; 3 4] >>diag(a) Type help matfun (Matrix functions - numerical linear algebra) in the Command Window for more information, or type help elmat (Elementary matrices and matrix manipulation). You may also type help <functionname> for help about a specific function. Matrix Operators We have the following basic matrix operations: We have the following array operators: The basic matrix operations can be modified for element-by-element operations by preceding the operator with a period. The modified operations are known as array operations.

LabVIEW MathScript Quick Reference 6/16 Colon Notation The colon notation is very useful for creating vectors: Note!

LabVIEW MathScript Quick Reference 7/16 Plotting Plots functions: Here are some useful functions for creating plots: Function Description Example plot Generates a plot. plot(y) plots the columns of y against the indexes of the columns. >X = [0:0.01:1]; >Y = X.*X; >plot(x, Y) figure Create a new figure window >>figure >>figure(1) subplot grid axis title xlabel ylabel legend Create subplots in a Figure. subplot(m,n,p) or subplot(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot. The axes are counted along the top row of the Figure window, then the second row, etc. Creates grid lines in a plot. grid on adds major grid lines to the current plot. grid off removes major and minor grid lines from the current plot. Control axis scaling and appearance. axis([xmin xmax ymin ymax]) sets the limits for the x- and y-axis of the current axes. Add title to current plot title('string') Add xlabel to current plot xlabel('string') Add ylabel to current plot ylabel('string') Creates a legend in the corner (or at a specified position) of the plot >>subplot(2,2,1) >>grid >>grid on >>grid off >>axis([xmin xmax ymin ymax]) >>axis off >>axis on >>title('this is a title') >> xlabel('time') >> ylabel('temperature') >> legend('temperature') hold Freezes the current plot, so that additional plots can be overlaid >>hold on >>hold off Type help graphics in the Command Window for more information, or type help <functionname> for help about a specific function. Below we see some examples of how to use the different plot functions:

LabVIEW MathScript Quick Reference 8/16 For line colors and line-styles we have the following properties we can use for the plot function: Line Styles: Colors: Marker specifiers:

LabVIEW MathScript Quick Reference 9/16 User-defined Functions MathScript includes more than 1000 built-in functions that you can use, but sometimes you need to create your own functions. To define your own function in MathScript, use the following syntax: function outputs = function_name(inputs) % documentation Here is the procedure for creating a user-defined function in MathScript: Note! It is recommended that you use lowercase in the function name. You should neither use spaces; use an underscore _ if you need to separate words. Example: function total = add(x,y) % this function add 2 numbers total = x+y;

LabVIEW MathScript Quick Reference 10/16 Flow Control If-Else Example: 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 x=-c/b; elseif c~=0 disp('no solution') else disp('any complex number is a solution') end Note! You have to use if n == 5 not if n = 5 The general syntax is as follows: if expression1 statements1 elseif expression2 statements2 else statements3 Switch-Case Statement Example: function result = calc_circle(r,x) switch x case 1 result=pi*r*r; case 2 result=2*pi*r; otherwise

LabVIEW MathScript Quick Reference 11/16 end disp('only 1 or 2 is legal values for x') The general syntax is as follows: switch variable case case_value1 statements1 case case_value2 statements2 otherwise statements end For Loop Example: 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 The general syntax is as follows: for variable = initval:endval end statement... statement

LabVIEW MathScript Quick Reference 12/16 While Loop Example: function f = fibonacci2(max) f(1)=0; f(2)=1; k=3; while f < max f(k)=f(k-1)+f(k-2); k=k+1; end The general syntax is as follows: while expression end statements

LabVIEW MathScript Quick Reference 13/16 Tips & Tricks Use the Script window not the Command window. You may use the Command window for simple things like, e.g., for getting help about specific functions, etc. help <function>. In the Script window you can save your code as so-called.m files. Comments - % % This is a comment x=2; y=3*x Use comments as part of your code to increase the readability of your program! Decimal point: Use a period (.) not comma (,) i.e. y=3.2 not y=3,2 File Names: Don t use spaces in filenames or in function names! Neither should you use the same names for your own functions as the built-in functions! Use Arrow Up and Arrow Down in order to browse previous used commands and functions in the Command Window A golden rule: One task one file, i.e. don t do all the tasks in one file! User-defined Functions: - Only one function in each.m file! - The filename (.m) and the name of the function need to be the same!

LabVIEW MathScript Quick Reference 14/16 Use semicolon (;) after commands/functions if you don t need to display the answer on the screen: a=2; b=4; y=a+b Use English names on variables, functions, files, etc. This is common practice in programming! Use always variables not use numbers directly in expressions a=2; b=4; y=a+b Not: y=2+4 Help: Use the help functionality in order to find out more about the functions you are going to use each function can be used in different manners. In order to get help for a specific function, type the following in the Command window: help <functionname> Always include the following commands on the top of your scripts: clear clc close all This make sure you don t get in trouble with old variables, figures, etc. Greek letters: In mathematics and control theory it is common to use greek letters in formulas, etc. These letters cannot be used directly in MathScript. So make sure to use good alternatives to these letter, ex.: w0 zeta or just z etc.

LabVIEW MathScript Quick Reference 15/16 Mathematical Expressions: In MathScript you can use the following: x^2 sqrt(x) log(x) Log10(x) exp(x) pi

Telemark University College Faculty of Technology Kjølnes Ring 56 N-3918 Porsgrunn, Norway www.hit.no Hans-Petter Halvorsen, M.Sc. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics E-mail: hans.p.halvorsen@hit.no Blog: / Room: B-237a