Some problems for your consideration

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Numerical Solution of Nonlinear Equations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Newton’s Method finds Zeros Efficiently finds Zeros of an equation: –Solves f(x)=0 Why do we care?
Open Methods Chapter 6 The Islamic University of Gaza
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Second Term 05/061 Roots of Equations Bracketing Methods.
Open Methods (Part 1) Fixed Point Iteration & Newton-Raphson Methods
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Roots of Equations Bracketing Methods.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 8 Roots of Equations Open Methods.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Roots of a Polynomial: Root of a polynomial is the value of the independent variable at which the polynomial intersects the horizontal axis (the function.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Java Coding 3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Over & over again!
Data Structures Chapter 1- Introduction Mohamed Mustaq.A.
Loop Application: Numerical Methods, Part 1 The power of Matlab Mathematics + Coding.
NEWTON’S METHOD/ MATLAB GRAPHICAL USER INTERFACE Caitlyn Davis-McDaniel and Dr. Scott Sarra Department of Mathematics, Marshall University, Huntington,
NETWONS METHOD DOING THAT JAWN I AM A BO$$ STUDENTS WILL BE ABLE TO USE NEWTON’S METHOD TO FIND THE ROOTS OF ALGEBRAIC EXPRESSIONS.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
PROGRAMMING TEST PROBLEMS. OUTLINE Newton-Raphson Method Lagrange Interpolating Polynomial.
Even more problems.. Mean (average) I need a program that calculates the average of student test scores. I need a program that calculates the average.
4.5: Linear Approximations, Differentials and Newton’s Method.
Numerical Methods for Engineering MECN 3500
4.5: Linear Approximations, Differentials and Newton’s Method Greg Kelly, Hanford High School, Richland, Washington.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Newton’s Method, Root Finding with MATLAB and Excel
Numerical Methods and Computational Techniques Solution of Transcendental and Polynomial Equations.
LINEARIZATION AND NEWTON’S METHOD Section 4.5. Linearization Algebraically, the principle of local linearity means that the equation of the tangent.
Linearization and Newton’s Method. I. Linearization A.) Def. – If f is differentiable at x = a, then the approximating function is the LINEARIZATION of.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
4.8 Newton’s Method Mon Nov 9 Do Now Find the equation of a tangent line to f(x) = x^5 – x – 1 at x = 1.
CONTROL STRUCTURE Chapter 3. CONTROL STRUCTURES ONE-WAY SELECTION Syntax: if (expression) statement Expression referred to as decision maker. Statement.
COMP Loop Statements Yi Hong May 21, 2015.
The formulae for the roots of a 3rd degree polynomial are given below
4.5: Linear Approximations, Differentials and Newton’s Method Greg Kelly, Hanford High School, Richland, Washington.
CSE 330: Numerical Methods. Introduction The bisection and false position method require bracketing of the root by two guesses Such methods are called.
CNG 140 C Programming (Lecture set 3)
4.5: Linear Approximations, Differentials and Newton’s Method
Java for Beginners University Greenwich Computing At School DASCO
The formulae for the roots of a 3rd degree polynomial are given below
4.5: Linear Approximations, Differentials and Newton’s Method
Some problems for your consideration
CiS 260: App Dev I Chapter 4: Control Structures II.
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Control Statement Examples
Chapter 4 Control structures and Loops
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
SELECTION STATEMENTS (2)
Computers in Civil Engineering 53:081 Spring 2003
Logical assertions assertion: A statement that is either true or false. Examples: Java was created in The sky is purple. 23 is a prime number. 10.
CSE 1020:Control Structure
Section 4.8: Newton’s Method
3.8 Newton’s Method How do you find a root of the following function without a graphing calculator? This is what Newton did.
4.8: Linear Approximations, Differentials and Newton’s Method
3.8: Newton’s Method Greg Kelly, Hanford High School, Richland, Washington.
4.5: Linear Approximations, Differentials and Newton’s Method
The formulae for the roots of a 3rd degree polynomial are given below
3.8: Newton’s Method Greg Kelly, Hanford High School, Richland, Washington.
5.5: Linearization and Newton’s Method
1 Newton’s Method.
EE, NCKU Tien-Hao Chang (Darby Chang)
The formulae for the roots of a 3rd degree polynomial are given below
Presentation transcript:

Some problems for your consideration

If What output will be produced by the following code: int extra = 2; if (extra < 0) System.out.println( "small" ); else if (extra == 0) System.out.println( "medium" ); else System.out.println( "large" );

If What output will be produced by the following code: int extra = -37; if (extra < 0) System.out.println( "small" ); else if (extra == 0) System.out.println( "medium" ); else System.out.println( "large" );

If What output will be produced by the following code: int extra = 0; if (extra < 0) System.out.println( "small" ); else if (extra == 0) System.out.println( "medium" ); else System.out.println( "large" );

Switch What is the output produced by the following code: char letter = 'B'; switch (letter) { case 'A' : case 'a' : System.out.println( "Some kind of A." ); case 'B' : case 'b' : System.out.println( "Some kind of B." ); break; default : System.out.println( "Something else." ); }

Switch What is the output produced by the following code: int key = 1; switch (key+1) { case 1 : System.out.println( "apples" ); break; case 2 : System.out.println( "oranges" ); case 3 : System.out.println( "peaches" ); case 4 : System.out.println( "plums" ); default : System.out.println( "fruitless" ); } When key is 3? When key is 5?

Boolean Let count be 0 and limit be 10 (the values for x and y are unknown). State whether each of the following is either true or false: (count==0) && (limit<20) count==0 && limit<20 (limit>20) || (count<5) !(count==12) (count==1) && (x<y) (count<10) || (x<y)

Depreciation The straight-line method for computing the yearly depreciation D for an item is given by: where P is the purchase price, S is the salvage value, and Y is the number of years the item is used. Write a program that takes as input the purchase price of an item, the expected number of years of service, and the expected salvage value. The program should then output the yearly depreciation for the item.

Babylonian algorithm for square root of n Steps: Make a guess at the answer (you can pick n/2 as your initial guess). Compute r = n / guess. Set guess = (guess+r) / 2. Go back to step 2 for as many iterations as necessary. The more you repeat steps 2 and 3, the closer guess will be to the square root of n. Write a program that inputs n, iterates through the algorithm 5 times, and outputs the answer as a double.

Newton-raphson method

Newton-Raphson method* *http://en.wikipedia.org/wiki/Newton%27s_method “In numerical analysis, Newton's method (also known as the Newton–Raphson method), named after Isaac Newton and Joseph Raphson, is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function.”

Newton-Raphson method The Newton-Raphson method in one variable: Given a function ƒ(x) and its derivative ƒ'(x), we begin with a first guess x0 for a root of the function. Provided the function is reasonably well-behaved, a better approximation x1 is: Geometrically, x1 is the intersection with the x-axis of a line tangent to f at f(x0).  

Newton-Raphson method Geometrically, x1 is the intersection with the x-axis of a line tangent to f at f(x0). The process is repeated until a sufficiently accurate value is reached:  

Newton-Raphson method Let f(x) be sin(x). (You will need to know f’(x). If you don’t know that, go to the Intershop and search for derivative of sin.) Write a Java program that calculates the first 5 steps of the Newton-Raphson method. Prompt the user for the start (x0). Output the result, x5, as well as sin(x5). Test with x0=1 and x0=2. What do you get different answers for x5?