1 / 40

MATLAB Tutorials

MATLAB Tutorials. Session V Mathematical Applications using MATLAB (Cont….). Rajeev Madazhy Email: rmadaz1@lsu.edu Dept of Mechanical Engineering LSU. Last Session…. Using fplot function Minimization Zero finding Curve fitting Interpolation Integration.

alyn
Télécharger la présentation

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 V Mathematical Applications using MATLAB (Cont….) Rajeev Madazhy Email: rmadaz1@lsu.edu Dept of Mechanical Engineering LSU

  2. Last Session…. • Using fplot function • Minimization • Zero finding • Curve fitting • Interpolation • Integration

  3. Session V Outline…. • Solving Double Integrals • Ordinary Differential Equations • Examples of ODE using MATLAB…. • Mention of DDE’s

  4. Solving Double Integrals…. Consider the numerical solution of Let We write a function to calculate the double integral using the MATLAB Inline function dblquad.

  5. MATLAB M-File…. Function out=integrnd(x,y) out= y*sin(x) + x*cos(y); To evaluate the double integral, use result = dblquad(‘integrnd’,xmin,xmax,ymin,ymax); at the command prompt.

  6. In MATLAB….

  7. Books on solving ODE’s using MATLAB.. Linear Algebra and Differential Equations Using MATLABMartinGolubitsky, MichaelDellnitz Ordinary Differential Equations Using MATLABJohn C.Polking & DavidArnold

  8. Solving ODE’s…. • MATLAB has the capability to solve the first order differential equations using numerical methods. • The functions used are ode23 and ode25 • Both ode23 and ode25 work the same way except for the internal algorithm that is being used. • Let us use ode45 in solving the Differential equations.

  9. Format…. • The format is as follows: • [t,y] = ode45(‘function_name’,tspan,y0) • function_name is the name of a function type file where the differential equation is stored. • tspan is a vector specifying the initial and final values of independent variable • y0 is a column vector containing the initial conditions • Results for the command are stored in vector y. • t is the vector of independent variable

  10. Example…. Solve a first order homogeneous differential equation with initial condition: We rewrite it as :

  11. Function in MATLAB… Write the function in MATLAB and save it as ode1.m

  12. Cont…. Write the following in another m-file:

  13. Result….

  14. Non-homogenous ODE’s…. If the differential equation is not homogenous then we do the following: It is rewritten again as follows:

  15. Solution…. All we need to do is change the function in the m-file ode1.m Rest remains the same as coded earlier.

  16. Higher order differential Equations…. • The higher order differential equations can be converted to a system of first order differential equations. • Next example shows how to solve second order differential equation using ode45 in Matlab

  17. c = 1 kg/s k = 100N/m m = 5 kg Problem…. The following figure shows a spring-mass-damper system. Plot the response of the system when the initial displacement of mass m is 0.1 meters.

  18. Equation of motion…. The equation of motion is as follows: Now we need to change it to first order equation to solve it. Rewriting the equation we get,

  19. Cont…. Consider the fact that is just velocity. So we can rewrite the equation as two first order differential equations

  20. Cont…. Or in general form we get:

  21. Cont…. Write the function as follows in Matlab editor and save it as ode2.m

  22. Cont…. Write the main program naming it as sorDiff.m Note that we have two initial conditions here.

  23. Velocity Response….

  24. Displacement Response….

  25. Exercise…. Write a Matlab program to determine the time-temperature history of a sphere of radius r=5mm, initially at a uniform temperature of 4000C. The sphere is exposed to 2000C air with a convection coefficient of h=10 W/m^2-K. The thermophysical properties of the sphere material are: =Density=3000kg/m^3 k=Thermal conductivity=20 W/m-K c=specific heat=1000J/kg-K

  26. Exercise cont…. The relation between the sphere temperature and time is given by an energy balance on the sphere, which results in the following differential equation where H = convective heat transfer coefficient T = temperature of the sphere at any time A = surface area of the sphere = 4r2 V = volume of the sphere = 4/3 r3 T = time

  27. Exercise cont…. This differential equation has the following exact solution which can be used to check the accuracy of the numerical solution provided by Matlab

  28. Exact Temperature code….

  29. Using as function….

  30. MATLAB main code….

  31. Result and plot….

  32. Delay Differential Equations… Ordinary differential equations (ODEs) and delay differential equations (DDEs) are used to describe many phenomena of physical interest. While ODEs contain derivatives which depend on the solution at the present value of the independent variable (“time”), DDEs contain in addition, derivatives which depend on the solution at previous times. DDEs are a better approximation than ODEs to many physical systems.

  33. Cont…. Consider a system of delay differential equations of the form: y(t) = f(t, y(t), y(t - τ1), y(t - τ2), . . . , y(t - τk)) that are solved on a ≤ t ≤ b with given history y(t) = S(t) for t ≤ a.

  34. Function code….

  35. Main program….

  36. Output….

  37. Website where you could obtain The dde23.m file….. http://www.radford.edu/~thompson/webddes/

  38. Recap…. • Solving Double Integrals • Ordinary Differential Equations • Examples of ODE using MATLAB…. • Mention of DDE’s

  39. Next Session…. • Engineering Applications using MATLAB…. • Solving non linear differential equations • Algorithm analysis • Common mechanical problems a) four bar linkage b) vibrations c) thermal and fluids

  40. Thank You

More Related