
solving nonlinear equations using MATHCAD.ppt
- Количество слайдов: 34
Lecture 2 Using Math. Cad for solving nonlinear equations
Introduction to the programming toolbar All the operators you need to use are contained on the Programming toolbar.
Programming toolbar ¡To open the Programming toolbar click View ->Toolbars -> Programming. ¡You may also click on the Programming Toolbar icon on the Math toolbar.
Creating a simple program ¡ ¡ You begin a Mathcad program by clicking on “Add Line. ” This inserts a vertical line with two placeholders. This is called the Programming Operator.
Task 1 ¡Create a program which checks a number and shows it if this number greater than 5 otherwise shows it with sign “-”. To defined conditions you should always use Programming Toolbar.
Task 2. ¡ This program uses the “AND” Boolean operator. Both statements must be true in order for the line to be true.
Task 2. ¡ This form of the program allows you to have an additional conditional statement branching off of the first conditional statement.
Task 3 ¡ ¡ Using Loops For and While find a sum of numbers from 1 to 10. You can define new variables within a program. These variables will be local to the program, meaning they will be undefined outside of the program. These are called local variables, and they are assigned with the local assignment operator – arrow pointing left ←.
Task 3 ¡ Create a user-defined function that will find the two roots of quadratic equation.
Bisection Method Calculation accuracy is 0. 001
Figure 1: Entered function on given interval with initial upper and lower guesses
Iteration 1
¡ ¡ Now, a new interval is selected based on which interval, (xl, xr) or (xr, xu), now brackets the root. To do this, the values of the functions at the three guesses must be known. Finding value of function at the lower and upper guesses and the estimated root
The new interval will be (xl, xr) if <0. It will be (xr, xu) if <0. Thus it is useful to redefine xl and xu based on this criteria.
Bisection method algorithm
Newton-Raphson Method
Iteration 1 ¡ The Newton Raphson Method works by taking a tangent line at the value of the function at the initial guess, and seeing where that tangent line crosses the x-axis. This value will be the new estimate for the root and can be obtained by using the following formula.
Figure 2: Entered function along given interval with current and next root and the tangent line of the curve at the current root ¡ While not necesary to the method, for graphing purposes we define the equation of the tangent line touching x 0.
Iteration 2 ¡ The same formula is used in iterations to calculate the next estimation of the root ¡ While not necesary to the method, for graphing purposes we define the equation of the tangent line touching x 1
Figure 3: Entered function along given interval with current and next root and the tangent line of the curve at the current root
Iteration 3 ¡ ¡ ¡ The same formula is used in iterations to calculate the next estimation of the root Calculate the distance between last two points. If the distance is less than calculation accuracy you should stop. It is less than calculation accuracy, so you should stop.
Newton-Raphson method algorithm
Secant Method
Iteration 1 ¡ ¡ The Secant method works very simliarly to the Newton-Raphson method, but instead of choosing one point and using the derivative of the function, two points are chosen and the secant line is used. So, first we must choose two initial guesses of the root. It should be noted that these two guesses do not have to bracket the root. We have called the two initial guesses and so that the first estimation of the root will be. It does not matter which guess is.
¡ Much like the Newton-Raphson Method, the approximation of the root will be where the secant line passing through both guesses crosses the x-axis. This value can be found using the following formula.
Figure 1: Entered function along given interval, secant line between the two guesses, and estimated root
Iteration 2 ¡ Using the same formula, calculate the next estimate of the root. ¡ Check the distance between two points
Secant line for the graph
Figure 2: Entered function along given interval, secant line between the two guesses, and estimated root
Iteration 3 ¡ Using the same formula, calculate the next estimate of the root. ¡ Calculation accuracy 0. 001 ¡ So, you should stop.
Secant method algorithm
Home task ¡ Make hand calculation using all methods. Take the same function from lecture 1.