tailieunhanh - Lecture note Data visualization - Chapter 30

This chapter presents the following content: Cubic spline interpolation, multidimensional interpolation, curve fitting, linear regression, polynomial regression, the polyval function, the interactive fitting tools, basic curve fitting, curve fitting toolbox, numerical integration. | Lecture 30 Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive Fitting Tools Basic Curve Fitting Curve Fitting ToolBox Numerical Integration Numerical Integration Example Here’s another example, using a function handle and an anonymous function, instead of defining the function inside single quote First define an anonymous function for a third-order polynomial fun_handle = @(x)-x.^3+20*x.^2-5 Now plot the function, to see how it behaves. The easiest approach is to use fplot , since it also accepts a function handle: fplot(fun_handle,[-5,25]) Example Continued . The integral of this function is area under the curve Finally, to evaluate the integral we’ll use the quad function, with the function handle as input: quad(fun_handle,0,25) ans = Solving Differential Equation Numerically MATLAB includes a number of functions that solve ordinary differential equations of the form . | Lecture 30 Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive Fitting Tools Basic Curve Fitting Curve Fitting ToolBox Numerical Integration Numerical Integration Example Here’s another example, using a function handle and an anonymous function, instead of defining the function inside single quote First define an anonymous function for a third-order polynomial fun_handle = @(x)-x.^3+20*x.^2-5 Now plot the function, to see how it behaves. The easiest approach is to use fplot , since it also accepts a function handle: fplot(fun_handle,[-5,25]) Example Continued . The integral of this function is area under the curve Finally, to evaluate the integral we’ll use the quad function, with the function handle as input: quad(fun_handle,0,25) ans = Solving Differential Equation Numerically MATLAB includes a number of functions that solve ordinary differential equations of the form numerically In order to solve higher-order differential equations they must be reformulated into a system of first-order expressions Not every differential equation can be solved by the same technique, so MATLAB includes a wide variety of differential equation solvers However, all of these solvers have the same format. This makes it easy to try different techniques by just changing the function name Continued . Each solver requires the following three inputs as a minimum: A function handle to a function that describes the fi rst-order differential equation or system of differential equations in terms of t and y The time span of interest An initial condition for each equation in the system The solvers all return an array of t- and y -values: [t,y] = odesolver(function_handle,[initial_time, final_time], [initial_cond_array]) If the resulting arrays [t,y] are not specified, the functions create a plot of the results Function Handle Input A function handle can refer to either a standard .