1 / 29

MATLAB Tutorials

MATLAB Tutorials. Session IV Mathematical Applications using MATLAB. Rajeev Madazhy Email: rmadaz1@lsu.edu Dept of Mechanical Engineering LSU. Department of Mechanical Engineering, LSU Session IV. Last Session…. Plotting in MATLAB 2-D Graphics 3-D Graphics

mura
Download Presentation

MATLAB Tutorials

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy Email: rmadaz1@lsu.edu Dept of Mechanical Engineering LSU Department of Mechanical Engineering, LSU Session IV

  2. Last Session…. • Plotting in MATLAB • 2-D Graphics • 3-D Graphics • Mesh, surface and contour plots in 3-D plots • Exercises in Graphics

  3. Session IV Outline…. • Using fplot function • Minimization • Zero finding • Curve fitting • Interpolation • Integration

  4. Using fplot() function…. fplot(fun,[xmin, xmax]) plots the function specified by the string fun between the x-axis limits specified by [xmin xmax]. For example fplot(‘sin(x)’,[0 2*pi]) will plot sine of x with x ranging from 0 to 2. Try it.

  5. Using fplot() function…. You can also use fplot for the function defined by yourself. >>fplot(‘function1’,[0 8]) where function1 is a M-file function: fun=‘function1’; fplot(fun,[0 8]) function y=function1(x) y=2*exp(-x).*sin(x);

  6. Output….

  7. Minimization…. • In many situations, we want to find the function extremes, the local maximum (peaks) and minimum (valleys). • fmin(fun,x1,x2) can be used to find a local minimum of function f(x) defined by string fun in the interval x1 < x < x2. • In order to find the local maximum, function f(x) should be replaced by -f(x).

  8. Example….

  9. Zero Finding…. • We have learned to use roots to find the zeros of a polynomial. • fzero(fun,x0) can be used to find zero of a general function f(x) near x0. • If you want to solve the equation f(x)=c, just define a function g(x)=f(x)-c. Then find the zero of g(x).

  10. Example….

  11. Curve Fitting by Polynomial Perform curve fit of N point of data (xi, yi) (i=1,…N) by a n-th order polynomial For example, n=4, f(x)=a0+a1*x+a2*x^2+a3*x^3+a4*x^4 Find a0, …, a4 which minimize the sum of the squared error at the data points Solve linear equations to find a0, …, a

  12. Using polyfit function…. • In Matlab, the function polyfit(x, y, n) finds the coefficients of a polynomial p(x) of degree n that fits the data provided by array x and y in a least-squares sense. • The program on next slide illustrates the use of this function

  13. Poly_fit M-File….

  14. Output….

  15. More on Curve Fitting…. • If x and y can be modeled by a power function or exponential function in the form y=a*x^b • y=a*exp(b*x) Taking natural logarithms of both side will yield ln(y)=ln(a)+b*ln(x) • ln(y)=ln(a)+b*x Then we can use the first order polynomial to fit the data and therefore find a and b

  16. Interpolation…. • Interpolation is defined as a way of estimating values of a function between those given by some set of data points. • The simplest way of interpolation is called linear interpolation in which the intermediate values are calculated by the straight line between the entered points. • Matlab provides function interp1 for one dimensional interpolation.

  17. Using interp1 function…. • yi = interp1(x,y,xi,'method'), where array x and y provide the data points that are known, yi is the result of interpolation at xi. • Available methods are: • 'nearest' - nearest neighbor interpolation • 'linear' - linear interpolation • 'spline' - cubic spline interpolation • 'cubic' - cubic interpolation The default is linear interpolation.

  18. Example…. Known temperature every hour for twelve hours. Find the temperature at 9.3 and 11.7 using interp1

  19. M-File….

  20. Output in command window….

  21. Example 2….

  22. Output….

  23. Integration…. Many engineering problems require the calculation of the definite integral of a function bounded in the finite interval [a, b]. Numerically, we can approximate the definite integral by the weighted sum of a number of function values

  24. Using trapz, quad, quad8 functions…. • Matlab provides three function , trapz, quad, quad8, for calculation of integrals. • The function trapz(x, y) calculates the integral by summing the area of trapezoids formed from the data points defined by array x and y • The function quad(fun, a, b) or quadl(fun, a, b) calculate the integral based on the concept of quadrature.

  25. Matlab M-File….

  26. Output….

  27. Recap…. • Using fplot function • Minimization • Zero finding • Curve fitting • Interpolation • Integration

  28. Next Session…. Ordinary Differential Equations…. Examples using MATLAB to solve ODE’s…. Mention of DDE’s….

  29. Thank You

More Related