SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 3”

Slides:



Advertisements
Similar presentations
Finding Complex Roots of Quadratics
Advertisements

You will learn about: Complex Numbers Operations with complex numbers Complex conjugates and division Complex solutions of quadratic equations Why: The.
Lecture 4 Structure plan Program design process Program design process Basic elements of code: Basic elements of code: –Input (assignment of variables)
Exercise (1).
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
CIS 101: Computer Programming and Problem Solving Lecture 7 Usman Roshan Department of Computer Science NJIT.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Basic operations in MATLAB Operation Symbol Example Addition+ 5+8 Subtraction- 5-8 Multiplication* 5*8 Division/ 5/8 Power^ 5^8 Lowest Highest 5+3/3*9.
Branches and Loops Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to Matlab. Entering Commands Constants and Functions >> pi ans = >> eps ans = e-016 >> sin(pi/2) ans = 1 >> log(1000) ans =
CSC 200 Lecture 3 1/27/06 Matt Kayala. Numerical Computation Maple example of Computer Algebra system –Symbolic Computation We could build a system like.
5.3 Solving Trigonometric Equations *use standard algebraic techniques to solve trig equations *solve trig equations in quadratic form *solve trig equations.
Trigonometric Functions
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
An Introduction to Scilab Tsing Nam Kiu 丁南僑 Department of Mathematics The University of Hong Kong 2009 January 7.
Chapter 10 Review: Matrix Algebra
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
6.5 – Solving Equations with Quadratic Techniques.
USER GUIDELINES OF: PARABOLIC PDE SOLVER Revision 2.11 of December 2, 2010 by M. MICCIO.
Matlab for Engineers Built-in Matlab Functions Chapter 3.
1.3 Console Input And Output academy.zariba.com 1.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Lecture 28: Mathematical Insight and Engineering.
MATLAB Trigonometry, Complex Numbers and Array Operations.
Goals: To solve quadratic equations by using the Quadratic Formula.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Factor: Factor: 1. s 2 r 2 – 4s 4 1. s 2 r 2 – 4s b b 3 c + 18b 2 c b b 3 c + 18b 2 c 2 3. xy + 3x – 2y xy + 3x – 2y -
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Introduction to Matlab
OUTLINE Overview Numbers, variables and similar in Matlab
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
5.3 – Solving Quadratic Equations by Factoring. Ex. 1 Solve y = x 2 + 5x + 6 by factoring.
The Quadratic Formula Students will be able to solve quadratic equations by using the quadratic formula.
Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular.
9.5 - The Quadratic Formula
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 12”
Limits Involving Trigonometric Functions
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Lecture 24: Rough and Ready Analysis. MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 4 Monday 06 Oct 2014 EGR 115 Introduction to Computing for Engineers.
9-4A Solving Quadratic Equations by Using the Quadratic Formula Algebra 1 Glencoe McGraw-HillLinda Stamper.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 3. Time Complexity Calculations.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Solving Quadratic Equations by Using the Quadratic Formula (9-5) Objective: Solve quadratic equations by using the Quadratic Formula. Use the discriminant.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Lesson 6.5: The Quadratic Formula and the Discriminant, pg. 313 Goals: To solve quadratic equations by using the Quadratic Formula. To use the discriminant.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Simple C Programs.
EEE 244-3: MATRICES AND EQUATION SOLVING
Aim: What are the properties of a quadratic equation?
Built-in MATLAB Functions Chapter 3
Computer Simulation Lab
MATLAB DENC 2533 ECADD LAB 9.
Lecture 4 Structure plan
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Cauchy–Euler Equation
EEE 244-3: MATRICES AND EQUATION SOLVING
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
Electrical and Computer Engineering Department SUNY – New Paltz
Computer Simulation Lab
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 3”

SUNY-New Paltz Developing algorithms  structure plan (pseudo- code)  systematic procedure or algorithm

SUNY-New Paltz Structure plans Solving Quadratic Equation ax 2 + bx + c = 0 Input data Second Order(a=0)? If not x=-c/b Is (b 2 -4ca)<0 If yes then complex roots Otherwise x 1,2 = (± b + √b2 − 4ac)/(2a)

SUNY-New Paltz Pseudo Code Start Input data (a, b, c) If a = 0 then If b = 0 then If c = 0 then Display ‘Solution indeterminate’ else Display ‘There is no solution’ else x = −c/b Display x (only one root: equation is linear) else if b2 < 4ac then Display ‘Complex roots’ else if b2 = 4ac then x = −b/(2a) Display x (equal roots) else x1 = (−b + √b2 − 4ac)/(2a) x2 = (−b − √b2 − 4ac)/(2a) Display x1, x2 Stop. Input data Second Order(a=0)? If not x=-c/b Is (b 2 -4ca)<0 If yes then complex roots Otherwise x 1,2 = (± b + √b2 − 4ac)/(2a)

SUNY-New Paltz MATLAB CODE (2) a = input('Enter a :'); b = input('Enter b :'); c = input('Enter c :'); if a == 0 if b == 0 if c == 0 display( 'Solution indeterminate!'); else display('There is no solution'); end else x==-c/b; display(['only one root: equation is linear, x=', num2str(x)]); end else if b*b < 4*a*c display('Complex roots') else if b*b == 4*a*c x = -b/(2*a) display(['equal roots, x1=x2=',num2str(x)]); else x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); display (['distinct roots x1=', num2str(x1),' x2=', num2str(x2)]); end Start Input data (a, b, c) If a = 0 then If b = 0 then If c = 0 then Display ‘Solution indeterminate’ else Display ‘There is no solution’ else x = −c/b Display x (only one root: equation is linear) else if b2 < 4ac then Display ‘Complex roots’ else if b2 = 4ac then x = −b/(2a) Display x (equal roots) else x1 = (−b + √b2 − 4ac)/(2a) x2 = (−b − √b2 − 4ac)/(2a) Display x1, x2 Stop.

SUNY-New Paltz Flow Chart N Y N N Y START INPUT COEFFICIENTS a = 0 ? b = 0 ? THERE IS NO SOLUTION! x=-c/b b 2 – 4ac>0 ? x 1,2 =( ±b+sqrt(b 2 – 4ac))/2a COMPLEX SOLUTIONS! c = 0 ? SOLUTION INDETERMINATE!

Y Y N SUNY-New Paltz MATLAB CODE (3) a = input('Enter a :'); b = input('Enter b :'); c = input('Enter c :'); if a == 0 if b == 0 if c == 0 display( 'Solution indeterminate!'); else display('There is no solution'); end else x==-c/b; display(['only one root: equation is linear, x=', num2str(x)]); end else if b*b < 4*a*c display('Complex roots') else if b*b == 4*a*c x = -b/(2*a) display(['equal roots, x1=x2=',num2str(x)]); else x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); display (['distinct roots x1=', num2str(x1),' x2=', num2str(x2)]); end N Y N N Y START INPUT COEFFICIENTS a = 0 ? b = 0 ? THERE IS NO SOLUTION! x=-c/b b 2 – 4ac>0 ? x 1,2 =( ±b+sqrt(b 2 – 4ac))/2a COMPLEX SOLUTIONS! c = 0 ? SOLUTION INDETERMINATE !

SUNY-New Paltz MATLAB functions x = ut cos(a), y = ut sin(a) − gt2/2 V = sqrt( (u * cos(a))^2 + (u * sin(a) - g * t)^2 );

Trigonometric Functions SUNY-New Paltz sin(x)sine of x cos(x)cosine of x. tan(x)tangent of x. cot(x)cotangent of x. asin(x)arc sine (inverse sine) of x between −π/2 and π/2. acos(x)arc cosine (inverse cosine) of x between 0 and π. atan(x)arc tangent of x between −π/2 and π/2. atan2(y, x)arc tangent of y/x between −π and π. sinh(x)hyperbolic sine of x cosh(x)hyperbolic cosine of x, tanh(x)hyperbolic tangent of x.. asinh(x)inverse hyperbolic sine of x, i.e. ln(x + √x2 + 1). acosh(x)inverse hyperbolic cosine of x, i.e. ln(x + √x2 − 1) atanh(x)inverse hyperbolic tangent of x, i.e.1/2 ln[(1 + x)/(1 − x)]. sec(x)secant of x. csc(x)cosecant of x.

SUNY-New Paltz Mathematical Functions abs(x)absolute value of x. log(x)natural logarithm of x. log10(x)base 10 logarithm of x. pow2(x)2 x exp(x)value of the exponential function ex randpseudo-random number in the interval [0, 1). realmaxlargest positive floating point number on your computer. realmin smallest positive floating point number on your computer rem(x,y)remainder when x is divided by y, e.g. rem(19, 5) returns 4 (5 goes 3 times into 19, remainder 4). max(x)maximum element of vector x. mean(x)mean value of elements of vector x. min(x)minimum element of vector x. cumsum(x)cumulative sum of the elements of x, e.g. cumsum(1:4) returns [ ] prod(x)product of the elements of x

SUNY-New Paltz Utility Functions clocktime and date in a six-element vector, e.g. the statements Datedate in a string in dd-mmm-yyyy format, e.g. 02-Feb-2001, which is thankfully Y2K compliant! tic, tocexecution time of code between these two functions is displayed. floor(x)largest integer not exceeding x, i.e. rounds down to nearest integer, e.g. floor(-3.9) returns -4, floor(3.9) returns 3 ceil(x)smallest integer which exceeds x, i.e. rounds up to nearest integer, e.g. ceil(-3.9) returns -3, ceil(3.9) returns 4 fix(x)rounds to the nearest integer towards zero, e.g. fix(-3.9) returns - 3, fix(3.9) returns 3 round(x)rounds to the integer nearest to x, e.g. round(4.49) returns 4, round(4.5) returns 5 plot(x,y) plot y versus x length(x)number of elements of vector x size(a)number of rows and columns of matrix a. sort(x)sorts elements of vector x into ascending order (by columns if x is a matrix). sign(x)returns -1, 0 or 1 depending on whether x is negative, zero or positive.

SUNY-New Paltz Exercises Plot sin(x) and cos(x) on the same axis Find the integers between 0 and that are divisible by 7 Find a random number between 1 and 10. Then repeat the process for N random numbers. Find the frequency of occurrence of the numbers ( 1 thru 10)