CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Lecture 1: Overview of Computers & Programming
CS 111: Introduction to Programming Midterm Exam NAME _________________ UIN __________________ 10/30/08 1.Who is our hero? 2.Why is this person our hero?
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C Programming
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
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.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Introduction to Programming with RAPTOR
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
1 Week 1: Variables, assignment, expressions READING: 1.2 – 1.4.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Basics of Matlab UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Programming Languages Programming languages are a compromise between spoken language and formal math. They allow humans to communicate with computers at.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
CS 177 Recitation Week 1 – Intro to Java. Questions?
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Software Engineering Algorithms, Compilers, & Lifecycle.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Software and Operating Systems
Programming Fundamental
Lecture: MATLAB Chapter 1 Introduction
2.5 Another Java Application: Adding Integers
MATLAB DENC 2533 ECADD LAB 9.
Introduction to C++ Programming
Use of Mathematics using Technology (Maltlab)
Understand the interaction between computer hardware and software
Experiment No. (1) - an introduction to MATLAB
Basics of Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Presentation transcript:

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

This is what computers are made of! The Uber Stack Applications Middleware Operating Systems Computers ProcessorsMemories Display Components Interconnects Materials Physics

How we Interact with Computers Applications Operating System Hardware User

Our CPU is at the core Fetch, Decodes, Executes Instructions in sequence

What is Software? Software = Programs Programs = a set of computer instructions for carrying out computing tasks Programmer = He or She that attempts to correctly structure those instructions to achieve a desired result !

Computer Programmers; a definition “Their rumpled clothes, their unwashed and unshaven faces, and their uncombed hair all testify that they are oblivious to their bodies and to the world in which they move. These are computer bums, compulsive programmers.”

Programmers having fun at work “ The trouble with programmers is that you can never tell what a programmer is doing until it ’ s too late. ”

Pseudo Code(ing) Allows you to write a program in english for the purpose of design without having to worry about specific computer language syntax and allows the programmer to concentrate on the logical sequences Start Input (amount) Amount = amount*4.33 If amount < 58 then print “It’s less than 58” Else print “It’s over 58” End

Programming Language A programming language is a convenient way of expressing instructions for a computer to execute Computer languages have evolved to the point where anyone can learn the basics of using one

Low and High Level Languages Programming languages are divided up into low- level languages and high-level languages. The closer the language is to machine language, the lower the level. High level languages make things easier to program.

Machine Language Every computer CPU has its machine language, the set of instructions it knows how to execute. This is the lowest level. A typical instruction might say, get the contents of a memory location and put it in the accumulator (perhaps in preparation for adding it to another number).

A Machine Language Program Put contents of memory location 10 in accumulator. Add contents of memory location 11 to accumulator. Put contents of accumulator back in location 10 It might look like …..not very user friendly! But believe it or not, computers were programmed in machine language at one time.

Natural Languages Computers don’t understand English Need to deal with Ambiguity Redundancy Literalness So, we express what a computer should do in a formal language

High-Level Languages In a high-level language the previous piece of code might look like this: Input current_balance current_balance = current_balance +new_check; store current_balance

Some High Level Languages Still in Use Today Fortran Basic PL/1 Cobol C C++ VISUAL BASIC Matlab LISP ADA JAVA PHP Python

Matlab Basics Starting Matlab double-click the Matlab icon, or in a terminal window, type matlab, and return The Command Window and the Matlab prompt >> The Desktop menu undocking command window tiling other windows (command history, workspace, current directory, profiler) The File menu Preferences The Help menu

Matlab Basics Matlab as a calculator Type expressions at the >>, and press return Result is computed, and displayed as ans Use numbers, +, *, /, -, (), sin, cos, exp, abs, round,… Precedence rules in expressions Left-to-right within a precedence group Precedence groups are (highest first) Highest precedence is parenthesis, then… Power (^) Multiplication and division (*, /) Addition and subtraction (+, -)

Examples of expressions Legal expressions >> 4 >> 5 + pi >> 6*sqrt(2)^4-12 >> 6 * sqrt( 2.0) ^ >> sin(pi/3)^2 + cos(pi/3)^2 >> 1.0/0.0 >> -4/inf >> 0/0 Illegal expressions >> 2 4 >> (2,4) Error messages –Read them carefully – a large portion of the time you will quickly figure out what is wrong

Variables Use names to assign result of an expression to a variable –Variables do not need to be declared before assignment A single “equal” sign (=) is the assignment operator, LHS = RHS Read this as –evaluate expression on the right-hand side, and then… – assign the result to the variable named on the left-hand-side Therefore –The right-hand-side needs to be a legal Matlab expression –The left-hand-side needs to be a single variable name (this will get more sophisticated later on) A semicolon at the end of the RHS expression suppresses the display, but the assignment still takes place.

Examples of Variables and Assignment Legal >> A = sqrt(13) >> B = exp(2); >> A = 2*B >> A = A + 1 >> C = tan(pi/4) Illegal (all for different reasons) >> D = sqrt(E) + 1; >> 3 = E >> 3*A = 14 >> F = 2 3

The “workspace” All variables that you create are accessible from the prompt >> Variables are accessed using their name as a reference Builtin Matlab commands >> who >> whos are used to see what is in the workspace. You can clear (ie, erase) variables with the clear command >> clear A clears the variable A from the workspace. How do we check that it worked?

Comparison (as opposed to assignment) Compare the equality of two expressions with a double equal sign, == Several arithmetic comparisons are available. Can also compare –greater than (with >) –less than (with <) –greater than or equal (with >=) –less than or equal (with <=), and –not equal (with ~=) The comparison is itself an expression –Its value is either 1 (true) or 0 (false), and can be used in assignment >> 5==sqrt(25) >> E = 1.72>tan(pi/3) What do you need to know to determine the result of >> E = 4>5-2 Precedence group is lower than addition and subtraction, so…

Quiting Matlab Type quit at the prompt, or Select Exit Matlab from the File menu However…

Saving the workspace When you “quit” Matlab, the variables in the workspace are erased from memory. If you need them for later use, you must save them. You can save all variables (or just some of them) to a file using the command save >> save saves all of the variables in the workspace into a file called matlab.mat (it is saved in the current directory) >> save Important A B C D* saves the variables A, B, C and any variable beginning with D in the workspace into a file called Important.mat

Loading from a.mat file load is the opposite of save. It reads a.mat file, putting all variables contained in the.mat file into the workspace >> load loads all of the variables from the file matlab.mat >> load Xenia loads all of the variables from the file xenia.mat There are no known security problems with load. Hence, you can safely send (as attachment), receive and use.mat files from others.

Complex Numbers All arithmetic in Matlab works on complex numbers as well. When you start Matlab, two variables already exist, and are equal to. They are i and j. It’s common to overwrite them without even realizing, but you can always create the number with the expression sqrt(-1) >> i >> sqrt(-1) >> j >> 4 + 6j >> 4 + 6*j >> C = 1 – 2i; >> real(C) >> imag(C) >> abs(C) >> angle(C)*180/pi

Syntax errors Violations of Matlab code Read them carefully Line number First error Error can help you solve issues

Help Documentation Help

Questions What is software? What is a program? Do we execute the code of a program?

Comments % Author: Nickolas Zeppos % Section 1, CS 170 % January 22, 2013 % HW Assignment 1

Figure window Plots Images

QUESTIONS??

Resources “Introduction to Programming with Matlab”, J. Michael Fitzpatrick and John D. Crocetti Lecture slides E77, Andy Packard, Lecture slides, The Digital World, Donald Stanford