Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
×

# Matlab II

1,118 views

Published on

Mekaniaka Software seminar on Matlab.
Differential Equations, Integration, Polynomials, Random Numbers etc

• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

### Matlab II

1. 1. DIFFERENTIAL EQUATIONS, INTEGRATION, POLYNOMIALS, RANDOM NUMBERS MEKANIKA SOFTWARE SEMINARS
2. 2. ODE INITIAL VALUE PROBLEMS <ul><li>ODE solvers handle the following types of first-order ODE’s: </li></ul><ul><ul><li>Explicit ODEs </li></ul></ul><ul><ul><li>Linearly implicit ODEs </li></ul></ul><ul><ul><li>Fully implicit ODEs </li></ul></ul><ul><li>ODE IVP solvers include: </li></ul><ul><ul><li>ode45 , ode23, ode113 (non-stiff DE’s) </li></ul></ul><ul><ul><li>ode23t, ode23tb (moderately stiff DE’s) </li></ul></ul><ul><ul><li>ode15s , ode23s (stiff DE’s) </li></ul></ul><ul><ul><li>ode15i (fully implicit DE’s) </li></ul></ul><ul><li>All ODE’s must be reduced to first order DE’s by substitutions before MATLAB can actually solve them. </li></ul>
3. 3. ODE IVP SYNTAX <ul><li>ODE syntax : </li></ul><ul><ul><li>[t,y] = solver (odefun , tspan , y0) </li></ul></ul><ul><ul><li>[t,y] = ode15i (odefun , tspan, y0, yp0) </li></ul></ul><ul><li>The odefun is generally given as a function handle: e.g. @function, where function defines the ODE. </li></ul><ul><li>Another parameter may be included in certain cases in the syntax, viz. options </li></ul><ul><li>For ode15i one must endeavor to use the decic function in MATLAB to compute consistent initial conditions. </li></ul><ul><li>[y0mod,yp0mod] = decic (odefun,t0,y0,fixed_y0,yp0,fixed_yp0) </li></ul>
4. 4. ODE BOUNDARY VALUE PROBLEMS <ul><li>Just as IVP’s require the initial conditions to be explicitly specified, BVP’s require boundary conditions to be specified. </li></ul><ul><li>While solving BVP’s we must give MATLAB a consistent and continuous initial solution from where to begin its iterations. To do this, we use the bvpinit function as: </li></ul><ul><li>solinit = bvpinit( x, yinit, parameters) </li></ul><ul><li>This generates an initial mesh from which bvpinit can form a good starting point for the BVP solver </li></ul><ul><li>The BVP solver is bvp4c, which solves 2-point BVP’s using a 3-stage finite difference Lobatto-Illa formula which is 4 th order uniformly accurate. </li></ul>
5. 5. ODE BVP SYNTAX <ul><li>sol = bvp4c(odefun,bcfun,solinit) </li></ul><ul><li>bcfun is a function that computes the residual in the boundary conditions. </li></ul><ul><ul><li>res = bcfun (ya,yb) </li></ul></ul><ul><li>solinit is a structure containing the initial guess for a solution. </li></ul>
6. 6. PARTIAL DIFFERENTIAL EQUATIONS <ul><li>c * δ u/ δ t = x -m * f + s </li></ul><ul><ul><li>c : coupling matrix; diagonal </li></ul></ul><ul><ul><li>m : symmetry of the problem </li></ul></ul><ul><ul><li>f : flux vector </li></ul></ul><ul><ul><li>s : source vector </li></ul></ul><ul><ul><li>all of the above are expressed as some function of </li></ul></ul><ul><ul><li>(x, t, u, δ u/ δ x) </li></ul></ul><ul><li>The PDE holds for t 0 <t<t f and a<x<b and must satisfy : </li></ul><ul><ul><li>IC : u(x, t 0 ) = u 0 (x) </li></ul></ul><ul><ul><li>BC : p(x,t,u) + q(x,t)*f = 0 </li></ul></ul>
7. 7. PDE SOLVER SYNTAX <ul><li>sol = pdepe (m,pdefun,icfun,bcfun,xmesh,tspan) </li></ul><ul><ul><li>[c,f,s] = pdefun (x,t,u,dudx) </li></ul></ul><ul><ul><li>u = icfun(x) </li></ul></ul><ul><ul><li>[pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t) </li></ul></ul><ul><ul><li>Vector [x0, x1, ..., xn] </li></ul></ul><ul><ul><li>Vector [t0, t1, ..., tf] </li></ul></ul><ul><li>sol is a 3-dimensional vector where sol(i , j , k) gives component k of the solution at time tspan(i) and the mesh point xmesh(j) </li></ul><ul><li>[uout ,DuoutDx] = pdeval (m,x,u(j,:),xout) </li></ul>
8. 8. NUMERICAL INTEGRATION <ul><li>Numerically evaluate with adaptive Simpson quadrature </li></ul><ul><ul><li>q = quad(fun,a,b,tol) </li></ul></ul><ul><li>Numerically evaluate with adaptive Lobatto quadrature </li></ul><ul><ul><li>q = quadl(fun,a,b,tol) </li></ul></ul><ul><li>Double integration </li></ul><ul><ul><li>q = dblquad(fun,xmin,xmax,ymin,ymax,tol) </li></ul></ul><ul><li>Triple Integration </li></ul><ul><ul><li>triplequad(fun,xmin,xmax,ymin,ymax,zmin,zmax) </li></ul></ul>
9. 9. IMPORTANT TRANSFORMS <ul><li>FOURIER TRANSFORM : F = fourier(f) </li></ul><ul><li>LAPLACE TRANSFORM : L = laplace(F) </li></ul><ul><li>Z-TRANSFORM : F = ztrans(f) </li></ul><ul><li>INVERSE FOURIER : F = ifourier(f) </li></ul><ul><li>INVERSE LAPLACE : L = ilaplace(F) </li></ul><ul><li>INVERSE Z-TRANSFORM : F = iztrans(f) </li></ul>
10. 10. POLYNOMIAL MANIPULATION <ul><li>CONVOLUTION : w = conv(u,v) </li></ul><ul><li>DECONVOLUTION : [q,r] = deconv(v,u) </li></ul><ul><li>RESIDUE : [r,p,k] = residue(b,a) </li></ul><ul><li>DERIVATIVE : k = polyder(p) </li></ul><ul><li>INTEGRATION : polyint(p,k) </li></ul><ul><li>CURVE FITTING : [p,S,mu] = polyfit(x,y,n) </li></ul><ul><li>EVALUATION : [y,delta] = polyval(p,x,S,mu) </li></ul>
11. 11. RANDOM NUMBER GENERATION <ul><li>UNIFORM RANDOM NUMBERS : Y = rand(m,n) </li></ul><ul><li>NORMAL RANDOM NUMBERS : Y = randn(m,n) </li></ul><ul><li>RANDOM PERMUTATION : p = randperm(n) </li></ul>