Lecture 4 Structure plan

Slides:



Advertisements
Similar presentations
Lecture 4 Structure plan Program design process Program design process Basic elements of code: Basic elements of code: –Input (assignment of variables)
Advertisements

SOLVING QUADRATICS General Form: Where a, b and c are constants.
Rational Equations and Partial Fraction Decomposition
Lecture 16 Symbolic Mathematics Symbolic mathematics: algebraezplotcalculus © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Solving Quadratic Equations Algebraically Lesson 2.2.
Lecture 3 Creating M-files Programming tools: Input/output(assign/graph-&-display) Repetition (for) Decision (if) © 2007 Daniel Valentine. All rights reserved.
1 Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Example: Solving Quadratic Equations Example:
Solving Quadratic Equations Tammy Wallace Varina High.
Factoring Polynomials
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Bell Ringer: Find the zeros of each function.
Copyright © Cengage Learning. All rights reserved.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Lesson 9.7 Solve Systems with Quadratic Equations
Section 10.5 – Page 506 Objectives Use the quadratic formula to find solutions to quadratic equations. Use the quadratic formula to find the zeros of a.
Notes - Solving Quadratic Equations in Factored Form If ab = 0, then a = 0 or b = 0 If the product of two factors is zero, then at least one of the factors.
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.
Solving Quadratic Equations by Factoring. Solution by factoring Example 1 Find the roots of each quadratic by factoring. factoring a) x² − 3x + 2 b) x².
DO NOW: FACTOR EACH EXPRESSION COMPLETELY 1) 1) 2) 3)
The Rational Root Theorem The Rational Root Theorem gives us a tool to predict the Values of Rational Roots:
Solving Quadratic Equations – Part 1 Methods for solving quadratic equations : 1. Taking the square root of both sides ( simple equations ) 2. Factoring.
Do Now : Evaluate when x = 6, y = -2 and z = The Quadratic Formula and the Discriminant Objectives Students will be able to: 1)Solve quadratic.
Example: 3x 2 + 9x + 6. Solving Quadratic Equations.
Copyright © 1999 by the McGraw-Hill Companies, Inc. Barnett/Ziegler/Byleen Precalculus: Functions & Graphs, 4 th Edition Chapter One Equations & Inequalities.
5-5 Solving Quadratic Equations Objectives:  Solve quadratic equations.
2.1 – Linear and Quadratic Equations Linear Equations.
Ch. 6.4 Solving Polynomial Equations. Sum and Difference of Cubes.
Topic VII: Polynomial Functions 7.3 Solving Polynomial Equations.
Section 5Chapter 6. 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Objectives 2 3 Solving Equations by Factoring Learn and use the zero-factor.
Objective: Use factoring to solve quadratic equations. Standard(s) being met: 2.8 Algebra and Functions.
Do Now Determine which numbers in the set are natural, whole, integers, rational and irrational -9, -7/2, 5, 2/3, √2, 0, 1, -4, 2, -11 Evaluate |x + 2|,
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.
1.2 Quadratic Equations. Quadratic Equation A quadratic equation is an equation equivalent to one of the form ax² + bx + c = 0 where a, b, and c are real.
Welcome! Grab a set of interactive notes
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
Chapter 4 Quadratic Equations
Equations Quadratic in form factorable equations
NON LINEAR FUNCTION Quadratic Function.
Solving Equations by Factoring
L2. Basics Variables and Expressions Assignment Statements
Quadratic Inequalities with 1 Variable (Interval analysis)
Copyright 2013, 2010, 2007, 2005, Pearson, Education, Inc.
Using the Quadratic Formula
The Discriminant Check for Understanding –
Symbolic mathematics: algebra ezplot calculus
Lecture 1: Introduction
Solving Equations by Factoring and Problem Solving
Solving Quadratic Equations by Completing the Square
Solve a system of linear equation in two variables
Find all solutions of the polynomial equation by factoring and using the quadratic formula. x = 0 {image}
Quadratic Formula & Discriminant
Solving Quadratic Equations by Completing the Square
P4 Day 1 Section P4.
Systems of Linear and Quadratic Equations
COMPASS Practice Test D
Standard Form Quadratic Equation
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.
The Discriminant Check for Understanding –
Copyright © Cengage Learning. All rights reserved.
Solving Polynomials by Factoring
Equations Quadratic in form factorable equations
6.8 Solving Equations by Factoring
The following slides contain repeats of information on earlier slides, shown without colour, so that they can be printed and photocopied. For most purposes.
Let’s see why the answers (1) and (2) are the same
Electrical and Computer Engineering Department SUNY – New Paltz
Objective SWBAT solve polynomial equations in factored form.
Concept 5 Rational expressions.
Section P4.
Presentation transcript:

Lecture 4 Structure plan Program design process Basic elements of code: Input (assignment of variables) Sequence of expressions Output (graphical or tabular) Structured approach to design © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.

Review of basic elements Input Initialize, define, request, or assign numerical values to variables. Set of commands Operations applied to input variables that lead to the desired result. Output Display (graphically or numerically) result.

A technical computing problem Let us examine the problem of computing the roots of a quadratic equation. We want to write a computer program to compute the roots of the following equation: a .* x.^2 + b .* x + c = 0 The structure plan is provided in the text and will be utilized in this lecture.

Structure plan Develop the structure plan, e.g.: Start (summary of Fig. 3.3 in the text) Input data (a, b, c) If a = 0, b = 0, and c = 0, indeterminate. If a = b = 0, no solution. If a = 0, x = -c/b; one root; equation is linear. If b^2 < 4ac, roots are complex. If b^2 = 4ac, roots are equal, x = b/(2a). If b^2 > 4ac, then the roots are: x1 = (-b + sqrt( b.^2 – 4.*a.*c)./(2.*a) x2 = (-b - sqrt( b.^2 – 4.*a.*c)./(2.*a) Stop Translate this plan to a program: Next slide.

Example: A program to solve for roots of quadratic equation given the coefficients a, b and c: Type this code in the editor and save it as quad_eqn.m.) % Quadratic equation % a .* x.^2 + b .* x + c = 0 % Step 1: Start format compact disp(' ') disp(' Quadratic roots finder ') % Step 2: Input data A = input(' Specify coefficients as follows: [a, b, c] = '); a = A(1);b = A(2);c = A(3); % Step 3: Evaluation of roots if a==0 & b==0 & c==0 disp(' Solution is indeterminate ') elseif a==0 & b==0 disp(' There is no solution ') elseif a==0 x = -c/b disp(' Only one root: equation is linear.') elseif b.^2 < 4.*a.*c disp(' Complex roots') elseif b.^2 == 4.*a.*c x = -b./(2.*a) disp(' Equal roots') else % b.^2 > 4.*a.*c x1 = (-b + sqrt(b.^2-4.*a.*c) )./(2.*a); x2 = (-b - sqrt(b.^2-4.*a.*c) )./(2.*a); disp(' x1,x2 the two distinct roots') disp([x1 x2]) end format % Step 4: Stop

Evaluation of the program A most important step: This program needs to be checked thoroughly! This can be done with polyval(), a tool to evaluate polynomials. Substitute the coefficients and computed roots into polyval as follows: coef = [a b c]; roots_of_quad = polyval(coef,[x1,x2]) Note: If results are zeros, then check is complete!

Exercise Evaluate the quad_eqn.m program as described in the previous slide: See next slide. Executing the program numerous times evaluating the results and comparing with known answers is important. You must be convinced, that every time you use the code to compute roots of a quadratic equation, it does it correctly!

Quadratic equation code with complex roots displayed & check % START OF CODE  SLIDE 1 of 3 % Quadratic equation roots based % on the theoretical formula for % the roots. D.T.V. .. Feb.2007. % % a .* x.^2 + b .* x + c = 0 % Modifications are in yellow. % Step 1: Start clear;clc format compact disp(' ') disp(' Quadratic roots finder ') % Step 2: Input data A = input(' Specify coefficients as follows: [a, b, c] = '); a = A(1); b = A(2); c = A(3);

% Step 3: Evaluation of roots SLIDE 2 of 3 if a==0 & b==0 & c==0 disp(' Solution is indeterminate ') elseif a==0 & b==0 disp(' There is no solution ') elseif a==0 x = -c/b x1 = x; x2=x; disp(' Only one root: equation is linear.') elseif b.^2 < 4.*a.*c x1 = (-b + sqrt(b.^2-4.*a.*c) )./(2.*a) x2 = (-b - sqrt(b.^2-4.*a.*c) )./(2.*a) disp(' Complex roots') elseif b.^2 == 4.*a.*c x = -b./(2.*a) x1=x;x2=x; disp(' Equal roots') else % b.^2 > 4.*a.*c x1 = (-b + sqrt(b.^2-4.*a.*c) )./(2.*a); x2 = (-b - sqrt(b.^2-4.*a.*c) )./(2.*a); disp(' x1,x2 the two distinct roots') disp([x1 x2]) end

This is the check at the end: format disp('check') coef = [a b c]; roots_of_quad = polyval(coef,[x1,x2]) % Step 4: Stop SLIDE 3 of 3 Note: Evaluation and validation of a computer program is the most time consuming and necessary effort to ensure that the tool produces reliable and correct results.

Summary The structure plan approach to design computer codes for technical computing was introduced by an example. Input assignment was illustrated with and without the ‘input’ utility. Graphical & tabular forms of output were shown. Illustrated array dot-operation, repetition (for) and decision (if) programming tools.