Example: tourism industry

MATLAB Examples - Numerical Differentiation

MATLAB ExamplesHans-Petter HalvorsenNumerical DifferentiationNumerical DifferentiationA Numerical approach to the derivative of a function = ( )is:Note! We will use MATLAB in order to find the numericsolution not the analytic solutionThe derivative of a function = ( )is a measure of how changes with . Numerical DifferentiationMATLAB Functions for Numerical Differentiation :diff()polyder() MATLAB is a Numerical language and do not perform symbolic mathematics .. well, that is not entirely true because there is Symbolic Toolbox available for DifferentiationGiven the following equation: = '+2 * +3 Find (use pen and paper ). Define a vector x from -5 to +5 and use the diff()function to approximate the derivative y with respect to x ( . /). Compare the data in a 2D array and/or plot both the exact value of the approximation in the same plot. Increase number of data point to see if there are any the following equation: = '+2 * +3 Then we can get the analytically solution: =3 *+4 1clearclcsymsf(x)symsxf(x) = x^3 + 2*x^2 -x +3dfdt= diff(f, x, 1)dfdt(x) = 3*x^2 + 4*x -1 This gives:Symbolic Math ToolboxWe start by finding the derivate of f(x) using the Symbolic Math Toolbox: = -5:1:5;% Define the function y(x)y= x.

Numerical Differentiation A numerical approach to the derivative of a function !=#(%)is: Note! We will use MATLAB in order to find the numericsolution –not the analytic solution The derivative of a function !=#(%) is a measure of how !changes with %.

Tags:

  Numerical, Matlab

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of MATLAB Examples - Numerical Differentiation

1 MATLAB ExamplesHans-Petter HalvorsenNumerical DifferentiationNumerical DifferentiationA Numerical approach to the derivative of a function = ( )is:Note! We will use MATLAB in order to find the numericsolution not the analytic solutionThe derivative of a function = ( )is a measure of how changes with . Numerical DifferentiationMATLAB Functions for Numerical Differentiation :diff()polyder() MATLAB is a Numerical language and do not perform symbolic mathematics .. well, that is not entirely true because there is Symbolic Toolbox available for DifferentiationGiven the following equation: = '+2 * +3 Find (use pen and paper ). Define a vector x from -5 to +5 and use the diff()function to approximate the derivative y with respect to x ( . /). Compare the data in a 2D array and/or plot both the exact value of the approximation in the same plot. Increase number of data point to see if there are any the following equation: = '+2 * +3 Then we can get the analytically solution: =3 *+4 1clearclcsymsf(x)symsxf(x) = x^3 + 2*x^2 -x +3dfdt= diff(f, x, 1)dfdt(x) = 3*x^2 + 4*x -1 This gives:Symbolic Math ToolboxWe start by finding the derivate of f(x) using the Symbolic Math Toolbox: = -5:1:5;% Define the function y(x)y= x.

2 ^3 + 2*x.^2 -x + 3;% Plot thefunctiony(x)plot(x,y)title('y')% Find nummericalsolutiontody/dxdydx_num= diff(y)./diff(x);dydx_exact= 3*x.^2 + 4.*x -1;dydx= [[dydx_num, NaN]', dydx_exact']% Plot nummericalvs analytical solution to dy/dxfigure(2)plot(x,[dydx_num, NaN], x, dydx_exact)title('dy/dx')legend('numeric al solution', 'analytical solution')Exact SolutionNumerical Solution = '+2 * +3 =3 *+4 1x = -5:1:5; =3 *+4 1x = -5 :5;x = -5 :5; Differentiation on PolynomialsGiven the following equation: = '+2 * +3 Which is also a polynomial. A polynomial can be written on the following general form: = 5 6+ 7 687+ + 687 + 6 We will use Differentiation on the Polynomialto find previous we know that the Analytically solution is: =3 *+4 1p = [1 2 -1 3];polyder(p) = '+2 * +3 =3 *+4 1ans=3 4 -1We see we get the correct answerDifferentiation on PolynomialsFind the derivative for the product:3 *+6 +9 *+2 We will use the polyder(a,b) function.

3 Another approach is to use define is to first use the conv(a,b)function to find the total polynomial, and then usepolyder(p) both methods, to see if you get the same Define the polynomialsp1 = [3 6 9];p2 = [1 2 0]; %Note!% Method1polyder(p1,p2)% Method2p= conv(p1,p2)polyder(p)As expected, the result are the same for the 2 methods used above. For more details, see next 36 42 18p =3 12 21 18 0ans=12 36 42 18We have that 1=3 2+6 +9and 2= 2+2 The total polynomial becomes then: = 1 2=3 4+12 3+21 2+18 As expected, the results are the same for the 2 methods used above: = (3 4+12 3+21 2+18 ) =12 3+36 2+42 +18 Hans-Petter Halvorsen, College of Southeast : ~hansha/


Related search queries