Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

Chapter 6: Roots: Open Methods
Review for Test 3.
APPLICATIONS OF DIFFERENTIATION
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
MAT 105 SP09 Functions and Graphs
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Chapter 4 Roots of Equations
INTEGRALS Areas and Distances INTEGRALS In this section, we will learn that: We get the same special type of limit in trying to find the area under.
INTEGRALS 5. INTEGRALS We saw in Section 5.1 that a limit of the form arises when we compute an area.  We also saw that it arises when we try to find.
MULTIPLE INTEGRALS Double Integrals over General Regions MULTIPLE INTEGRALS In this section, we will learn: How to use double integrals to.
Do Now: p.381: #8 Integrate the two parts separately: Shaded Area =
Introduction In an equation with one variable, x, the solution will be the value that makes the equation true. For example: 1 is the solution for the equation.
College Algebra Fifth Edition James Stewart Lothar Redlin Saleem Watson.
Copyright © Cengage Learning. All rights reserved. Quadratic Equations, Quadratic Functions, and Complex Numbers 9.
 1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99.
Techniques of Integration
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Chapters 5 and 6: Numerical Integration
MATLAB FUNDAMENTALS: INTRO TO LINEAR ALGEBRA NUMERICAL METHODS HP 101 – MATLAB Wednesday, 11/5/2014
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Chemistry 330 The Mathematics Behind Quantum Mechanics.
DOUBLE INTEGRALS OVER GENERAL REGIONS
AP CALCULUS PERIODIC REVIEW. 1: Limits and Continuity A function y = f(x) is continuous at x = a if: i) f(a) is defined (it exists) ii) iii) Otherwise,
1. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphing Linear Equations and Inequalities CHAPTER 4.1The Rectangular.
4.6 Graphing with Calculus and Calculators In this section, we will learn about: The interaction between calculus and calculators. APPLICATIONS OF DIFFERENTIATION.
Copyright © Cengage Learning. All rights reserved. Functions.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 4 : Polynomial Edward Cheung Room W311g 2008.
Chapter 7 Polynomial and Rational Functions
Linear Equations in Two Variables
Chapter 3 Roots of Equations. Objectives Understanding what roots problems are and where they occur in engineering and science Knowing how to determine.
FUNCTIONS AND MODELS 1. The fundamental objects that we deal with in calculus are functions.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
Section 2.1 Complex Numbers. The Imaginary Unit i.
Mathematics for Business and Economics - I
Numerical Differentiation and Quadrature (Integration)
College Algebra Acosta/Karwoski. CHAPTER 1 linear equations/functions.
Analyzing Functions (4.16) y=f(x) MATLAB. Functional Analysis includes: Plotting and evaluating a function Finding extreme points Finding the roots (zeros.
Functions and Their Representations
Interval Notation Interval Notation to/from Inequalities Number Line Plots open & closed endpoint conventions Unions and Intersections Bounded vs. unbounded.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
SECTION 12.5 TRIPLE INTEGRALS.
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.
INTEGRALS We saw in Section 5.1 that a limit of the form arises when we compute an area. We also saw that it arises when we try to find the distance traveled.
5 INTEGRALS.
Date: 1.2 Functions And Their Properties A relation is any set of ordered pairs. The set of all first components of the ordered pairs is called the domain.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Functions 2 Copyright © Cengage Learning. All rights reserved.
MTH55_Lec-51_sec_8-3a_Quadratic_Fcn_Graphs.ppt 1 Bruce Mayer, PE Chabot College Mathematics Bruce Mayer, PE Licensed Electrical.
Chapter 3 Graphs and Functions. § 3.1 Graphing Equations.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Copyright © Cengage Learning. All rights reserved. 4 Integrals.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Graphing a Linear Inequality Graphing a linear inequality is very similar to graphing a linear equation.
EEE 244-3: MATRICES AND EQUATION SOLVING
Graphing Equations and Inequalities
Two-Dimensional Plots
MATLAB DENC 2533 ECADD LAB 9.
College Algebra Fifth Edition
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
Warm-up (10 min.) I. Factor the following expressions completely over the real numbers. 3x3 – 15x2 + 18x x4 + x2 – 20 II. Solve algebraically and graphically.
Arab Open University Faculty of Computer Studies Dr
EEE 244-3: MATRICES AND EQUATION SOLVING
Chapter 2 Functions, Equations, and Graphs
Presentation transcript:

Numerical Analysis 3D Plots

A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.

SOLVING AN EQUATION WITH ONE VARIABLE Can write an equation with one (independent) variable in form f(x) = 0 A solution or root of the equation is a value of the variable that makes the equation be true, i.e., that makes f(x) have the value zero Making the equation be true is called satisfying the equation

Graphically, a solution is a point where the function f(x) touches or crosses the x-axis. Although mathematically if a value of x makes the function touch the x- axis but not cross it that value is a root, in MATLAB the value must make the function cross the x-axis in order to be considered a root SOLVING AN EQUATION WITH ONE VARIABLE

The equation f(x) = 0 can have No solutions Example: f(x) = 0 has no solutions if f(x) = 5 A finite number of solutions Example (one solution): f(x) = 0 has exactly one solution if f(x) = x Example (two solutions): f(x) = 0 has exactly two solutions if f(x) = 1 – x2 An infinite number of solutions Example: f(x) = 0 has an infinite number of solutions if f(x) = sin( x ) SOLVING AN EQUATION WITH ONE VARIABLE

A numerical solution or root is a value of x that makes the function be zero or almost zero A general procedure for finding a numerical solution is: SOLVING AN EQUATION WITH ONE VARIABLE

1. The user provides an initial guess of the numerical root, which the procedure uses as its current estimate of the numerical root 2. If the current estimate makes the function be almost zero, use that estimate as the numerical root and stop computing 3. If the current estimate does not make the function be almost zero, find a new estimate that makes the function be closer to zero and go to Step 2

The procedure lets the user define what "almost zero" means, e.g., the absolute value of the estimate must be < Another way for the procedure to stop is when the current and previous estimates are almost the same The procedure lets the user define "almost the same", e.g., absolute value of the difference is less than 10 -4

SOLVING AN EQUATION WITH ONE VARIABLE Use the MATLAB function fzero() to find a root of a function fzero is a function that accepts another function (the function to be solved) as an input argument (like fplot that we saw before). You can also use an inline (anonymous) function.

x0 can be a scalar or a two-element vector If it is a scalar, it has to be a value of x near the point where the function crosses the x-axis If it is a vector, the two elements have to be points on opposite sides of the solution This implies that f(x0(1)) and f(x0(2)) have different signs SOLVING AN EQUATION WITH ONE VARIABLE

If a function has more than one solution, you can find the different solutions by calling fzero once for each solution and passing a different initial value x0 each time If function is a polynomial, using roots to find the solutions will give you all of them at once. A good way to get an initial value is to plot the function and see where it crosses the x-axis SOLVING AN EQUATION WITH ONE VARIABLE

In many applications you can estimate the domain of the solution Often when a function has more than one solution only one of the solutions will have a physical meaning SOLVING AN EQUATION WITH ONE VARIABLE

fzero finds zeros of a function only if they cross the x- axis, not just touch it If fzero can't find a solution, it returns NaN >> 0.1 ) % touches at x=0 Exiting fzero: aborting search for an interval containing a sign change because NaN or Inf function value encountered during search. (Function value at e+154 is Inf.) Check function or try again with a different starting value. ans = NaN SOLVING AN EQUATION WITH ONE VARIABLE

fzero has many options. To see them all, type help fzero in Command Window or use Help Window One useful option [x fval] = fzero(function,x0) returns the value of function at x. You can get this value easily on your own but the above saves a little typing SOLVING AN EQUATION WITH ONE VARIABLE

Parabola with roots at 0 and 2 >> parabola - (t-1)^2; Find a zero >> x = fzero( parabola, 4 ) x = 2 Get function value at the zero >> parabola( x ) ans = 0 Do both at once >> [x fval] = fzero( parabola, 4 ) x = 2 fval = 0

Example: Parabola with roots at 0 and 2 >> parabola - (t-1)^2; % find a zero >> x = fzero(parabola, 4) x = 2 % function value at zero >> parabola(x) ans = 0

You can use fzero to find where a function has a particular value. Suppose you have f(x) = 0 and you want to find the x that makes f(x) = 3. You can rewrite this as f(x) - 3 = 0 and then, defining g(x) = f(x) – 3, use fzero to find the root (solution) of g(x). Example: x 3 +5x = 10 becomes x 3 + 5x – 10 = 0. Solving an Equation with One Variable >> g = 'x^3+5*x-10'; >> x = fzero(g, 1) x = fplot (g, [0,2]) grid on

Can also use fzero to find where a function has a particular value. Suppose given f(x)=0 and want to find the x that makes f(x)=3. Can rewrite this as f(x)-3=0, and, defining g(x) = f(x) – 3, use fzero to find root of g(x) SOLVING AN EQUATION WITH ONE VARIABLE

FINDING A MINIMUM OR A MAXIMUM OF A FUNCTION Often want to find the minimum or maximum of a function y = f(x) in a certain region of the horizontal axis. Can do that with [x fval] = fminbnd(function,x1,x2)

FINDING A MINIMUM OR A MAXIMUM OF A FUNCTION [x fval]= fminbnd(function,x1,x2) function can be a string or a handle function must accept a single scalar x function must return a single scalar – the value of the function at x x1 and x2 are the left and right boundaries of the region on the x-axis, i.e., x1 < x2 always

>> - 12*x^ *x ; >> [x fval] = fminbnd(f, 0, 8) x = fval = >> [x fval] = fminbnd(f, 0.5, 2) x = fval = Finding a Minimum of a Function

Function is entered as a string or a function handle (like fzero). quad uses the numerical technique called the "adaptive Simpson method". It calculates the integral with an absolute error smaller than 1.0e–6 The user must make sure that the function does not approach a vertical in the interval [a,b]. Numerical Integration - quad

q = quad( function, a, b ) Can enter function as string expression or function handle Same as with fzero in Section 9.1 quad calculates integral with absolute error smaller than 1.0e–6 Can change this number by adding optional tol argument to the command, i.e., q = quad(function,a,b,tol) tol defines maximum. Smaller value gives more accurate answer but takes longer to compute NUMERICAL INTEGRATION

Function is entered as a string or a function handle (like fzero). It is used exactly like quad. quadl uses the numerical technique called the "adaptive Lobatto method" which can be more efficient for high accuracies and smooth integrals. The user must make sure that the function does not approach a vertical in the interval [a,b]. Numerical Integration - quadl It is a lower case L

>> f >> simpson = quad (f,0,2) simpson = >> lobatto = quadl (f,0,2) lobatto = Numerical Integration - Example

The trapz command: q = trapz( x, y ) Use when given (x,y) points, not function Often occurs with experimental data Uses trapezoidal method of numerical integration x and y must be same length the values in x must be in ascending order NUMERICAL INTEGRATION

Use trapz when you have coordinate (x,y) points, not a function (like experimental data). It uses the trapezoidal method of numerical integration. x and y must be of the same length. The values in x must be in ascending order. Numerical Integration - trapz >> x = [ ]; >> y = [ ]; >> q = trapz(x, y) q = 40

Three-dimensional (3-D) plots useful for presenting related 3-D points. Common cases are Scalar or vector function of two- independent variables Scalar or vector data measurements in 3-D space Movement over time 3-D space THREE-DIMENSIONAL PLOTS

LINE PLOTS A three-dimensional line plot is a plot obtained by connecting points in 3- D space. MATLAB command is x,y, and z must be same size Remaining arguments are same as in 2-D plots (Section 5.1)

Here is a first example of the plot3 command. Simple, linear but rather dull. x = [ ]; y = [ ]; z = [ ]; plot3 (x,y,z) grid on 3D Line Plots

Let's look at a more beautiful plot. a = [0:0.001:4*pi]; b = sin (a); c = cos (a); plot3 (a,b,c) grid on 3D Line Plots

Let's look at this very pretty and colorful one. t = 0:0.1:6*pi; x = sqrt(t).* sin (2*t); y = sqrt(t).* cos (2*t); z1 = 0.5 * t; z2 = 0.5 * t; z1 = t; z3 = 0.25*t; plot3(x,y,z1,'b',x,y,z2,'r',x,y,z3,'g','linewidth',2) 3D Line Plots

3D MESH AND SURFACE PLOTS Mesh and surface plots are 3-D plots used to graph functions of the form z = f(x,y) x and y are independent variables, z is a dependent variable A mesh plot connects values of z with lines to form the outline of a surface A surface plot connects lines in a mesh plot with planes to show a solid representation of the surface

Three steps to making mesh or surface plot 1. Create grid in the x-y plane that contains points you're interested in 2. Calculate the value of z at every point of the grid 3. Make the plot MESH AND SURFACE PLOTS

Creating a grid in the x y plane (Cartesian coordinates): The grid is the set of points on which you want to evaluate z. For example MESH AND SURFACE PLOTS

Note that X is made of identical rows because each row of grid has the same x-coordinates Y is made of identical columns because each column of grid has same y-coordinates To make matrices, use MATLAB command

Z = X.*Y.^2./ (X.^2 + Y.^2) 3D Mesh and Surface Plots

The mesh command permits the creation of wireframe mesh colored graphs in 3D. The third dimension must be a matrix created from meshgrid and some other operation. Here is a simple example: x = [ ]; y = [ ]; z = [ ]; [X,Y] = meshgrid (x,y); Z = X.*Y; mesh (X,Y,Z) 3D Mesh and Surface Plots Grid on by default. grid off to remove

The surf command permits the creation of surface-colored graphs in 3D. It works exactly like the mesh command. Here is a simple example: x = [ ]; y = [ ]; z = [ ]; [X,Y] = meshgrid (x,y); Z = X.*Y; surf (X,Y,Z) 3D Mesh and Surface Plots

Again let's see more beautiful plots. c = [-pi:0.1:pi]; d = [-pi:0.1:pi]; [C,D] = meshgrid (c,d); E = sin (C).* sin (D); mesh (C,D,E) surf (C,D,E) 3D Mesh and Surface Plots

You can change the surface shading with the shading command (shading faceted is the default seen on the previous slide). shading flat shading interp 3D Mesh and Surface Plots

Additional comments on the mesh command: MATLAB colors surface plots with colors that vary with value of z Can make color constant by using the Plot Editor in the Figure Window or by using colormap command. ( See Help on colormap for details) By default, mesh draws a grid. Issue command grid off to prevent grid from appearing Can draw box around plot with box on MESH AND SURFACE PLOTS

You can also change the coloring of the graph with colormap. colormap (gray) colormap (cool) colormap (hot) 3D Mesh and Surface Plots

PLOTS WITH SPECIAL GRAPHICS Polar coordinates grid in the x y plane : To make 3-D plot of function z = f(r,θ) 1. Make grid of values of θ and r with meshgrid 2. Compute value of z at each grid point 3. Convert grid with polar coordinates to grid with Cartesian coordinates using MATLAB's pol2cart command 4. Make 3-D plot using values of z and the Cartesian coordinates

3D Plots for Special Graphs - Sphere It is extremely easy to plot a sphere. The sphere function returns the coordinates of a sphere with a specified number of faces (20 if the number is not specified). [X,Y,Z] = sphere (10); mesh (X,Y,Z) [X,Y,Z] = sphere (50); surf (X,Y,Z) shading interp colormap cool [X,Y,Z] = sphere (100); surf (X,Y,Z)

THE view COMMAND The view command controls direction from which you view plot. Command is view(az,el) or view([az el]) az – azimuth: angle (in degrees) in x y plane measured from negative y axis and positive in counterclockwise direction el – elevation: angle of elevation (in degrees) from x y plane. Positive in direction of positive z axis

Default view angles are az = -37.5o and el = 30o az = -37.5o and el = 30oaz = 20o and el = 35o THE view COMMAND

Can project 3-D curve onto 2-D plane by specific settings of azimuth and elevation See book examples of projections THE view COMMAND

END OF LESSON