259 Lecture 10 Spring 2013 Advanced Excel Topics – More User Defined Functions; Conditional Statements.

Slides:



Advertisements
Similar presentations
Introductory Algebra Glossary Chapter Ten Free powerpoints at
Advertisements

Finding Complex Roots of Quadratics
What are you finding when you solve the quadratic formula? Where the graph crosses the x-axis Also known as: Zeros, Roots and X-intercepts.
Equations of parallel, perpendicular lines and perpendicular bisectors
EXAMPLE 4 Use the discriminant Find the discriminant of the quadratic equation and give the number and type of solutions of the equation. a. x 2 – 8x +
Quadratic Graph Drawing.
Released Items Aligned to McDougal Littell “Algebra 1” Copyright 2007
Chapter 8 Graphing Linear Equations. §8.1 – Linear Equations in 2 Variables What is an linear equation? What is a solution? 3x = 9 What is an linear equation.
The Quadratic Formula..
Solving Equations. Is a statement that two algebraic expressions are equal. EXAMPLES 3x – 5 = 7, x 2 – x – 6 = 0, and 4x = 4 To solve a equation in x.
Solving Quadratic Equations Section 1.3
4.8: Quadratic Formula HW: worksheet
Objectives: To solve quadratic equations using the Quadratic Formula. To determine the number of solutions by using the discriminant.
Quadratic Equations, Functions, and Models
Perpendicular Bisector of a Line To find the equation of the perpendicular bisector of a line segment : 1. Find the midpoint 2. Find the slope of the given.
5.6 Quadratic Equations and Complex Numbers
Aim: The Discriminant Course: Adv. Alg, & Trig. Aim: What is the discriminant and how does it help us determine the roots of a parabola? Do Now: Graph.
Solving Quadratic Equations Using Completing the Square and the Quadratic Formula.
Module :MA0001NP Foundation Mathematics Lecture Week 9.
The Quadratic Formula. What does the Quadratic Formula Do ? The Quadratic formula allows you to find the roots of a quadratic equation (if they exist)
Pre-Calculus Section 1.5 Equations Objectives: To solve quadratics by factoring, completing the square, and using the quadratic formula. To use the discriminant.
Review – Quadratic Equations All quadratic equations do not look the same, but they all can be written in the general form. y = a·x 2 + b·x + c where a,
Chapter 10 Review for Test. Section 10.1:Graph y = ax² + c Quadratic Equation (function) _____________ Parabola is the name of the graph for a quadratic.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
5.6 – Quadratic Equations and Complex Numbers Objectives: Classify and find all roots of a quadratic equation. Graph and perform operations on complex.
Quadratic Formula You can use this formula to find the solutions(roots) to a quadratic equation. This formula can be broken up into 2 parts: b 2 – 4ac.
The Quadratic Formula Students will be able to solve quadratic equations by using the quadratic formula.
WARM UP EVALUATING EXPRESSIONS Evaluate the expression for the given value of the variable (Lesson 2.5). 1.-3(x) when x = 9 2.4(-6)(m) when m = (-n)(-n)
Linear Inequalities Page 178. Formulas of Lines Slope Formula Slope Intercept Form Point Slope Form Ax + By = C Standard Form A,B,C ∈ℤ, A ≥ 0 Ax + By.
Vertex and Axis of Symmetry. Graphing Parabolas When graphing a line, we need 2 things: the y- intercept and the slope When graphing a parabola, we need.
Solving Quadratic Formula using the discriminant.
Chapter 4: Polynomial and Rational Functions. 4-2 Quadratic Equations For a quadratic equation in the form ax 2 + bx + c = 0 The quadratic Formula is.
Slope: Define slope: Slope is positive.Slope is negative. No slope. Zero slope. Slopes of parallel lines are the same (=). Slopes of perpendicular lines.
Aim: How do we solve quadratic equation with complex roots? Do Now: 1. Solve for x: 2. Solve for x: 3. Solve for x: HW: p.219 # 6,8,10,12,14 p.241 # 6,14,25.
5.6 – Quadratic Equations and Complex Numbers Objectives: Classify and find all roots of a quadratic equation. Graph and perform operations on complex.
Warm-Up Use the quadratic formula to solve each equation. 6 minutes 1) x x + 35 = 02) x = 18x 3) x 2 + 4x – 9 = 04) 2x 2 = 5x + 9.
Remember slope is a rate of change so it is the difference of the y coordinates over the difference of the x coordinates. Precalculus Functions & Graphs.
Warm Up  1.) Write 15x 2 + 6x = 14x in standard form. (ax 2 + bx + c = 0)  2.) Evaluate b 2 – 4ac when a = 3, b = -6, and c = 5.
3.4 Chapter 3 Quadratic Equations. x 2 = 49 Solve the following Quadratic equations: 2x 2 – 8 = 40.
SOLVE QUADRATIC EQUATIONS BY USING THE QUADRATIC FORMULA. USE THE DISCRIMINANT TO DETERMINE THE NUMBER AND TYPE OF ROOTS OF A QUADRATIC EQUATION. 5.6 The.
259 Lecture 10 Spring 2017 Advanced Excel Topics – More User Defined Functions; Conditional Statements.
4.6 Quadratic formula.
Discriminant and Quadratic
The Discriminant Given a quadratic equation, can youuse the
Chapter 4 Quadratic Equations
Introductory Algebra Glossary
Solving quadratics methods
Nature of Roots of a Quadratic Equation
Sum and Product of Roots
COORDINATES, GRAPHS AND LINES
Section 5-3: X-intercepts and the Quadratic Formula
4.6 Quadratic formula.
Math 20-1 Chapter 4 Quadratic Equations
Quadratic Equations, Functions, Zeros, and Models
Coordinate Plane Sections 1.3,
9-6 The Quadratic Formula and Discriminant
Finding the Midpoint To discover the coordinates of the midpoint of a segment in terms of those of its endpoints To use coordinates of the midpoint of.
Chapter 8 Quadratic Functions.
WARM UP 3 EVALUATING RADICAL EXPRESSIONS Evaluate the radical expression when a = -1 and b = 5. (LESSON 9.1). b 2 − 11a b 2 +9a a 2 +8.
Preliminaries 0.1 THE REAL NUMBERS AND THE CARTESIAN PLANE 0.2
Write an equation in point-slope form for the perpendicular bisector of the segment with endpoints P(5, 2) and Q(1, –4). Step 1 Graph PQ. The perpendicular.
Chapter 8: Graphs and Functions
Solving Quadratic Equations by the Graphical Method
Warm Up #4 1. Write 15x2 + 6x = 14x2 – 12 in standard form. ANSWER
Graphing Linear Equations
Functions and Their Graphs
Chapter 1 Review Functions and Their Graphs.
quadratic formula. If ax2 + bx + c = 0 then
Writing the equation of the
Presentation transcript:

259 Lecture 10 Spring 2013 Advanced Excel Topics – More User Defined Functions; Conditional Statements

Outline  More User Defined Functions! Perp_Bisector_Slope() Perp_Bisector_Intercept() Quadratic_1() Quadratic_2()  Pseudo Code  IF…THEN…ELSE Statements Modified Quadratic Function A Piecewise Defined Function 2

Perp_Bisector_Slope()  Example 1: Create a user defined function Perp_Bisector_Slope() that will return the slope of the line that is the “perpendicular bisector” of the line segment determined by the points (x 1,y 1 ) and (x 2,y 2 ). 3

Perp_Bisector_Slope()  Given: Points (x 1,y 1 ) and (x 2,y 2 ). Line L is the perpendicular bisector of the line segment determined by the points (x 1,y 1 ) and (x 2,y 2 ).  Find: The slope of line L. 4

Perp_Bisector_Slope()  Pseudo Code: (1) Find the slope of the line segment determined by the points (x 1,y 1 ) and (x 2,y 2 ), and then store the result in the variable m1. (2) Find the negative reciprocal of m1 and then store the result in the variable m2. (3) Return the value stored in the variable m2 as the result of the user defined function. 5

Perp_Bisector_Slope() Function Perp_Bisector_Slope(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double 'Returns the slope of the line that is the '"perpendicular bisector" of the line segment 'determined by points (x1,y1) and (x2,y2). 'The function does NOT work for vertical lines Dim m1 As Double, m2 As Double m1 = (y2 - y1) / (x2 - x1) 'negative reciprocal of m1 m2 = -1 / m1 Perp_Bisector_Slope = m2 End Function 6

Perp_Bisector_Intercept()  Example 2:Create a user defined function Perp_Bisector_Intercept() that will return the y-intercept of the line that is the “perpendicular bisector” of the line determined by the points (x 1,y 1 ) and (x 2,y 2 ). 7

Perp_Bisector_Intercept()  Given: Points (x 1,y 1 ) and (x 2,y 2 ). Line L is the perpendicular bisector of the line segment determined by the points (x 1,y 1 ) and (x 2,y 2 ).  Find: The y-intercept of line L. 8

Perp_Bisector_Intercept()  Pseudo Code: (1)Find the slope of the line by using the Perp_Bisector_Slope(x 1, y 1, x 2, y 2 ) function previously defined, and then store the result in the variable m. (2)Find the x-component of the midpoint of the line segment, and then store the result in the variable Midpoint_X. (3)Find the y-component of the midpoint of the line segment, and then store the result in the variable Midpoint_Y. (4)Return the y-intercept of line L, by substituting the coordinates of the midpoint into the expression y -m*x. 9

Perp_Bisector_Intercept() Function Perp_Bisector_Intercept(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double 'Returns the y-intercept of the line that is the 'perpendicular bisector" of the line segment 'determined by points (x1,y1) and (x2,y2). 'The function does NOT work for vertical lines Dim m As Double Dim Midpoint_X As Double, Midpoint_Y As Double m = Perp_Bisector_Slope(x1, y1, x2, y2) Midpoint_X = (x1 + x2) / 2 Midpoint_Y = (y1 + y2) / 2 'b = y - m*x 'put in a known point (Midpoint_X, Midpoint_Y) on the line Perp_Bisector_Intercept = Midpoint_Y - m * Midpoint_X End Function 10

Quadratic_1()  Example 3:Create a user defined function Quadratic_1() that will return the first real root of a quadratic equation Ax 2 + Bx + C = 0. 11

Quadratic_1()  Given: A, B, and C Roots of Ax 2 + Bx + C = 0 are and  Find: The first real root of a quadratic equation Ax 2 + Bx + C = 0. 12

Quadratic_1()  Pseudo Code: (1) Substitute the A, B, and C values into the formula and return the result of this expression. 13

Quadratic_1() Function Quadratic_1(A As Double, B As Double, C As Double) As Double 'Returns the first real root of a quadratic equation 'Ax^2+Bx+C=0 'Does NOT return a complex root Quadratic_1 = (-B + Sqr(B ^ * A * C)) / (2 * A) End Function 14

Quadratic_2()  Example 4: Create a user defined function Quadratic_2() that will return the second real root of a quadratic equation Ax 2 + Bx + C = 0. 15

Quadratic_2()  Given: A, B, and C Roots of Ax 2 + Bx + C = 0 are and  Find: The second real root of a quadratic equation Ax 2 + Bx + C = 0. 16

Quadratic_2()  Pseudo Code: (1) Substitute the A, B, and C values into the formula and return the result of this expression. 17

Quadratic_2() Function Quadratic_2(A As Double, B As Double, C As Double) As Double 'Returns the first real root of a quadratic equation 'Ax^2+Bx+C=0 'Does NOT return a complex root Quadratic_1 = (-B - Sqr(B ^ * A * C)) / (2 * A) End Function 18

IF…THEN…ELSE Statements  Just like in Excel, we can create conditional statements within VBA!  One of the most useful conditional statements in VBA is the IF…THEN…ELSE statement! 19

IF…THEN…ELSE Syntax  Syntax: If condition_1 Then result_1 ElseIf condition_2 Then result_2... ElseIf condition_n Then result_n Else result_else End If  How the command works:  condition_1 to condition_n are evaluated in the order listed.  Once a condition is found to be true, the IF…THEN…ELSE statement will execute the corresponding code and not evaluate the conditions any further.  result_1 to result_n is the code that is executed once a condition is found to be true.  If no condition is met, then the Else portion of the IF…THEN…ELSE statement will be executed.  Note that the ElseIf and Else portions are optional. 20

Quadratic_1_Improved()  Example 5:Modify the Quadratic_1() user defined function to return the first root (real or complex).  For example x 2 +4x+8=0 should return (2+2i) and x 2 +5x+6=0 should return -2.  Then modify the VBA code for this new function to make a user defined function to find the other root! 21

Quadratic_1_Improved()  Given:A, B, and C Roots of Ax 2 + Bx + C = 0 are:  Find: The first root of a quadratic equation Ax 2 + Bx + C = 0. 22

Quadratic_1_Improved()  Pseudo Code: (1)If B^2 – 4AC  0, then substitute the A, B, and C values into the formula and return the value of this expression. (2)Otherwise, put the A, B, and C values into the formula and store the result in the variable Real_Part. (3)Substitute the A, B, and C values into the formula and store the result in the variable Imaginary_Part. (4)Return the string value “{Real_Part} + {Imaginary_Part} i “ by substituting the actual numeric values for Real_Part and Imaginary_Part into {Real_Part} and {Imaginary_Part}. 23

Quadratic_1_Improved() Function Quadratic_1_Improved(A As Double, B As Double, C As Double) As Variant 'Returns the first root of a quadratic equation Ax^2+Bx+C=0 'Returns both real and complex roots Dim Real_Part As Double, Imaginary_Part As String If B ^ * A * C >= 0 Then Quadratic_1_Improved = (-B + Sqr(B ^ * A * C)) / (2 * A) Else Real_Part = -B / (2 * A) Imaginary_Part = Sqr(Abs(B ^ * A * C)) / (2 * A) Quadratic_1_Improved = Str(Real_Part) + "+ " + Str(Imaginary_Part) + "i" End If End Function 24

A piecewise “user defined function” f(x)  Example 6: Use VBA IF statement(s) to create the following piecewise “user defined function” f(x):  Plot a graph of this function! 25

A piecewise “user defined function” f(x) Function f(x As Double) As Double 'Returns x^3, if x<0 'Returns x^2, if 0<=x<=3 'Returns Sqr(x-3), if x>3 If x<0 Then f = x^3 End If If (x >= 0) And (x <= 3) Then f = x^2 End If If (x>3) Then f = Sqr(x-3) End If End Function 26

27 References  User Defined Functions Notes – John Albers  IF…THEN…ELSE Statements (p. 20 of this lecture) - ormulas/if_then.php ormulas/if_then.php