Physics 114: Lecture 1 Overview of Class Intro to MATLAB

Slides:



Advertisements
Similar presentations
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Advertisements

EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
TERMS TO KNOW. Programming Language A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks. Each language has.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Input, Output, and Processing
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
The purpose of a CPU is to process data Custom written software is created for a user to meet exact purpose Off the shelf software is developed by a software.
John Federici NJIT Physics Department
Development Environment
John Federici NJIT Physics Department
Topics Designing a Program Input, Processing, and Output
Release Numbers MATLAB is updated regularly
Introduction to Eclipse
Lesson 1 - Sequencing.
Lesson 1 An Introduction
Physics 114: Final Project Hints
Lecture: MATLAB Chapter 1 Introduction
Introduction to Programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Variables, Expressions, and IO
Other Kinds of Arrays Chapter 11
DEPARTMENT OF COMPUTER SCIENCE
Installing R and R Studio
PHP Introduction.
Intro to PHP & Variables
MATLAB DENC 2533 ECADD LAB 9.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Lecture 1: Introduction
Introduction to Programming
Introduction to Python
Use of Mathematics using Technology (Maltlab)
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Introduction to Java, and DrJava part 1
Lecture 2 Introduction to MATLAB
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Lesson 2: Input and Variables
Communication and Coding Theory Lab(CS491)
Topics Designing a Program Input, Processing, and Output
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
Introduction to Java, and DrJava
Introduction to MATLAB
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
INC 161 , CPE 100 Computer Programming
Topics Designing a Program Input, Processing, and Output
Experiment No. (1) - an introduction to MATLAB
Summary of what we learned yesterday
Topics Designing a Program Input, Processing, and Output
Using Script Files and Managing Data
Introduction to Programming
12th Computer Science – Unit 5
Introduction to Java, and DrJava part 1
Computer Simulation Lab
IS 135 Business Programming
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Physics 114: Lecture 1 Overview of Class Intro to MATLAB John Federici NJIT Physics Department

TRIVIA QUESTION! Which “Big Bang Theory” character is an Optical Physicist? (a) Raj Koothrappali (b) Bernadette Rostenkowski (c) Howard Wolowitz (d) Sheldon Cooper (e) Amy Farrah Fowler (f) Leonard Hofstadter (g) Penny a b c d e f g

Course WEBPAGE Course Webpage — The course webpage is accessible from my web page https://web.njit.edu/~federici/ Follow the link for Phys 114 Course Notes, Syllabus, Grades etc. — Will be posted on the course web page. Course Textbook — Available (should be) in NJIT book store. Course Software — MATLAB. It is available FREE to you on the NJIT website. Please download it in the next few days to make sure that you can get it operational on your computer. Why MATLAB? Its free to NJIT students. It is one of the ‘standard’ software packages for analyzing data. Widely used. … I use it in my research. If you want to use ANOTHER software package, eg. Mathcad, Mathematica, etc. etc., please see me. No need to write your own C++, Java, etc. code. Why “reinvent the wheel?” Bring you Laptop (if you can) to class — We will be doing some class participation problems.

Why take this class? Required of all Applied Physics Majors for graduation You will meet other Applied Physics majors. The skills which you will learn How to properly prepare journal-quality plots and images How to use Matlab The limits of detection, measurement error, etc. are useful for ALL of your science courses, independent study (research as an undergraduate), and your career AFTER NJIT. Watching “The Big Bang Theory” is required…… (just kidding). If you take my OPSE 301 course, I EXPECT you to know how to use MATLAB. Other faculty will expect the same.

Downloading MATLAB http://ist.njit.edu/software/

Downloading Software Go to http://ist.njit.edu/software/download.php If you are OFF-Campus, you will first need to download and install VPN (Virtual Private Network) software BEFORE you download other software:

Follow Install Instructions

Next, install Matlab

Run Matlab Search for Help Click here for Getting Started resources

Enter commands (line by line) in the command window Line by line processing of commands Variables you create

Some simple tips: Use UP and DOWN arrows to scroll through previous commands Use “;” to suppress printing of output Use “;” and put more than one command on a line Double-click on WORKSPACE Variable to open up a spreadsheet with data.

TRIVIA QUESTION! What does “Matlab” stand for? (a) Mathematics Lab (b) Mathew’s Labrador – Name of founder’s dog (c) Sheldon Cooper’s Laboratory name (d) Matrix Laboratory (e) Mat Lab – The ‘doorway’ entrance to computational tools.

More Simple Tips: SAVE your Matlab code as a script You may want to use your script later. You may want to keep a ‘working’ copy before you edit it. You can import the script into other software programs (eg. Labview) Use “%” to annotate your script. WHY do you THINK you should annotate your script? Save a script Open a NEW script Type in your Matlab code

Open and then Run *.m files Use OPEN icon to open a matlab file/ script (*.m) Use RUN icon to run the code “Run-time” errors will appear in the command window Run a script Open a script

Matlab Language Fundamentals Search in help for “Language Fundamentals”

Matlab: Numeric Types On the www.mathworks.com website, you can find HOW TO videos. For example, here is one on Matlab fundamentals https://www.mathworks.com/videos/introducing-matlab-fundamental-classes-data-types-101503.html Numeric classes in MATLAB® include signed and unsigned integers, and single-precision and double-precision floating-point numbers. By default, MATLAB stores all numeric values as double-precision floating point. (You cannot change the default type and precision.) You can choose to store any number, or array of numbers, as integers or as single-precision to save space compared to double precision. By default, MATLAB® displays numeric output as 5-digit scaled, fixed-point values. Values are SAVED as double precision, but only 5 digits are displayed. You can change display using “format” command >> format long >> 1/11 ans = 0.090909090909091 >> format short 0.0909 >>

Matlab: Data types For now, we will focus on some of the simplier data types in Matlab: Numbers and Arrays (which includes vectors), and Text

Manipulation of Arrays If A is an array, then you can perform same operations on ALL elements in array a = 1 2 3 4 5 6 7 8 9 >> a+10 ans = 11 12 13 14 15 16 17 18 19 >> cos(a) 0.5403 -0.4161 -0.9900 -0.6536 0.2837 0.9602 0.7539 -0.1455 -0.9111 >>

Array versus Matrix Operations Array operations work on corresponding elements of arrays with equal dimensions. Each element in the first operand gets matched up with the element in the same location in the second operand. If the inputs are different sizes, then MATLAB cannot match the elements one-to-one. These are ELEMENT by ELEMENT manipulations Eg. A+B means “Parallel Processing” of multiple elements A.*B means Matrix operations DO NOT work on corresponding elements of arrays. The size of outputs and inputs depend on the mathematical operation. A*B means Standard Matrix Multiplication

Text data Define a STRING by putting alphanumeric characters in ‘quotes’ >> year=2017; >> DateString='The year is '; >> TempString=[DateString,int2str(year),'. HAPPY NEW YEAR!']; >> disp(TempString) The year is 2017. HAPPY NEW YEAR! >> As you would expect, there is standard syntax to concatenate strings and to convert numeric data (eg. int2str, num2str, sprintf) to string data. Display a STRING with ‘disp’ NOTE: Some functions interpret a ‘FORMAT SPECIFIER Differently…

Text data - continued NOTE: Some functions interpret a ‘FORMAT SPECIFIER Differently… >> i=5; >> str1=int2str(i) str1 = 5 >> str2=num2str(i,'%3d') str2 = >> str3=sprintf('%3d',i) str3 = >> NOTE: for sprintf function, spaces PAD on the left to ensure that the string is 3 characters long while for num2str, the same format string DOES NOT PRODUCE SAME RESULTS

Class Exercise: Write a Simple Matlab program Use Matlab HELP or DOCUMENATION SEARCH as needed Create a script which will calculate the number of days in a year using the following method. Create a ROW matrix of 12 elements. Call the matrix “DaysInMonths”. For each element, use the number of days in each month…. Eg. January has 31 days, February has 28 days, etc. Sum all of the elements and assign that value to the variable NumDaysInYear. Have the NumDaysInYear displayed in Matlab Once you have your code working so that you get the CORRECT answer, create a new script and SAVE your commands and at lease ONE annotation to the script. Save the file as a matlab script. HINT: You can cut and paste from COMMAND window to EDITOR window. Use up/ down arrows to scroll through previous commands.