MATLABApplicationofMATLABinDi®erentialEquations():::::200111501004:00MATLAB::00[]MATLABMATLABM[]MATLABAbstract:Inthearticle,wediscusstheapplicationofMATLABindi®erentialequations,includingsolvingmethodbysymbolandbynumericalofordinarydi®erentialequations,and¯niteelementmethodofpartialdi®erentiaequation.Weprovidesomefunc-tionalcommandofsolvingdi®erentialequationsinMATLAB,inordertosolvefunctionwecompileM¯leonthebasisofalgorithm,wegettheresultassameastheoreticalestimate.Keywords:MATLABOrdinaryDi®erentialEquation;PartialDi®erentialEqua-tionEulerMethod;FiniteElementMethod.¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢1MATLAB¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢1MATLAB¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢2hi¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢2hi¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢31.MATLAB(ODE)¢¢¢¢42.M¢¢¢¢11MATLAB¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢19hi(FiniteElementMethod)¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢19hiPDE¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢20¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢26¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢27¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢28¡¡2080MATLABMathematicaMapleMathCADMATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABMathworksMATLAB(MatrixLaboratory)LINPACKEISPACK20012002MathworksMATLABMATLAB6.0MATLAB6.5MATLABMATLAB21MATLABMATLAB:1²²²²²²MATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABMATLABhiMATLABdsolve:²dsolve(0equ01;0equ02;¢¢¢;0equ0k)²dsolve(0equ01;0equ02;¢¢¢;0equ0k;0s0)%s²dsolve(0equ1;equ2;¢¢¢0;0equk¢¢¢0)%equttDd=dtDD2d2=dt2D3y(t)3Dy(a)=bDy(b)=byabc1;c2dsolve:²²²2:1y=dsolve(0Dy=f(y)0)y,[u;v]=dsolve(0Du=f(u;v);Dv=g(u;v)0)u;v,s=dsolve(0Du=f(u;v);Dv=g(u;v)0)s:x;s:y1Àdsolve(0Dx=¡a¤x0)%ans=c1¤exp(¡a¤t)2Àx=dsolve(0Dx=¡a¤x0;0x(0)=10;0s0)%stx=exp(¡a¤s)3À[u;v]=dsolve(0Du=v;Dv=¡u0;0u(0)=0;v(0)=10;0x0)%xu=sin(x)v=cos(x)4Às=dsolve(0Df=f+g0;0Dg=¡f+g0;0f(0)=10;0g(0)=20)%s=f:[1£1sym]g:[1£1sym]%Às:f%ans=exp(t)¤(cos(t)+2¤sin(t))Às:gans=exp(t)¤(¡sin(t)+2¤cos(t)):(1)Às=dsolve(0Df=f+g0;0Dg=¡f+g0;0f(0)=10;0g(0)=20)Às=dsolve(0Df=f+g;Dg=¡f+g0;0f(0)=10;0g(0)=20)Às=dsolve(0Df=f+g;Dg=¡f+g0;0f(0)=1;g(0)=20)Às=dsolve(0Df=f+g;Dg=¡f+g;f(0)=1;g(0)=20)(2)dsolve00hi3MATLAB1.MATLAB(ODE):8:y0=F(t;y);a·t·b;yy(a)=y0MATLAB:(1):yn=y(n¡1);yn¡1=y(n¡2);¢¢¢;y2=y0;y1=y(2)():8:y0=F(t;y);a·t·b;yy(a)=y0:y000¡3y00¡y0¡y=0;y(0)=0;y0(0)=1;y00(0)=¡1y1=y;y2=y0;y3=y00:8:y10=y2y20=y3y30=3¢y3+y2+y18:y1(0)=0y2(0)=1y3(0)=¡1(2)MF:mfuctiondy=F(t;y)%tydy=[y(2);y(3);3¤y(3)+y(2)+y(1)]%dy(3):[T;Y]=solver(0F0;tspan;y0)%solverFMtspan[t0;tfinal]y0t0TYTY[T;Y]=solver(0F0;tspan;y0;options)options[T;Y;TE;YE;IE]=solver(0F0;tspan;y0;options)%optionsonTEYEIE[T;Y]=solver(0F0;tspan;y0;options;p1;p2;¢¢¢)4%P1;P2;¢¢¢F(T;Y;FIAG;P1;P2):²ODEode23ode45ode113ode15sode23sode23tode15iode23tb²odesetodeget²odeplotodephas2odephas3odeprint²ODEorbt2oderigidodevdpodeODE:2solverODEode4545R-K(4x)3ode2323R-K(4x)3ode113Admsode4510¡3»10¡6ode23t10¡3»10¡6ode15sGear0sode45ode23s2Rosebrockode15sode15iMATLAB7:0ode15iMAYTLAB:MATLABODE:MAYTLABode23ode45ode113ode15sode23s¢R-Kode45ode45MATLAB:[T;Y]=ode45(0F0;tspan;y0)%5FMf(x;y)TYtspan[t0;tf]t0tf[t0;t1;¢¢¢;tn]y0t0[T;Y]=ode45(0F0;tspan;y0;options)%options[T;Y]=ode45(0F0;tspan;y0;options;p1;p2;¢¢¢)%p1;p2;¢¢¢FF(T;Y;flag;p1;p2;¢¢¢)[T;Y;TE;YE;IE]=ode45(0F0;tspan;y0;options)optionsonTEYEIEMATLAB:functiondy=funname(t;y)functiondy=funname(t;y;flag;p1;p2;¢¢¢)ttMATLAByDyflagoptionsoptionsodeset()optionsoptionsodeset()options10¡7options=odeset(0Reltol0;1e¡7);options=odeset;options:Reltol=1e¡7;63Reltol0.01Abstol10¡6MaxstepMassJacobianJacobi@f=@xJacobip1;p2;¢¢¢;pmflag5:8:y01=y1¡0:01¤y1¤y2;y1(0)=30;y02=¡y2+0:02¤y1¤y2;y2(0)=20:y1y2M:biomodel:mfunctionbiofun=biomodel(t;y)biofun=[y(1)¡0:01¤y(1)¤y(2);¡y(2)+0:02¤y(1)¤y(2)]:Àtspan=0:0:1:20;Ày0=[30;20];À[t;y]=ode45(0biomodel0;tspan;y0);À[t;y];Àsubplot(1;2;1);Àplot(t;y);ÀgridÀgtext(0g(1)0);Àgtext(0g(2)0);Àsubplot(1;2;2);Àplot(y(:;1);y(:;2))ÀgridÀxlabel(0y10);ylabel(0y20):71MATLAB6()Lorenz:8:_y1(t)=¡¯y1(t)+y2(t)¢y3(t)y1(0)=0_y2(t)=¡½y2(t)+½y3(t)y2(0)=0_y3(t)=¡y1(t)¢y2(t)+¾y2(t)¡y3(t)y3(0)=1e¡10¯=83;½=10;¾=28¯½¾Mlorenz1:mfunctionydot=lorenz1(t;y;flag;beta;rho;sigma)ydot=¡beta¤y(1)+y(2)¤y(3);¡rho¤y(2)+rho¤y(3);¡y(1)¤y(2)+sigma¤y(2)¡y(3)%flag:Ày0=[0;0;1e¡10]Àtspan=[0;100]Àb1=83;r1=10;s1=28;%betaÀ[t;y]=ode45(0lorenz10;tspan;y0;[];b1;r1;s1);Àsubplot(1;2;1);Àplot(t;y);Àsubplot(1;2;1);Àplot3(y(:;1);y(:;2);y(:;3));8Àaxis([1042¡2020¡2025]);:2options[]M¯½¾lorenz1:m¢R-Kode23ode23ode45ode45:[T;Y]=ode23(0F0;tspan;y0)%F:y0=F(t;y);tspan[t0;tf]t0tf[t0;t1;¢¢¢;tn]y0[T;Y]=ode23(0F0;tspan;y0;options)%optionsode45[T;Y]=ode23(0F0;tspan;y0;options;p1;p2;¢¢¢)%optionsoptions=[]tspany0ode23ode[tspan;y0;options]=F([];[];0init0)ode23;ode23(0F0)[T;Y;TE;YE;IE]=ode23(0F0;tspan;y0;options)9optionsonTEYEIE¢ode15sode45MATLABODE7y0(t)=y(t)¡2t=y(t);y(0)=1;0t4y=p1+2tneÀodefun=inline(0y¡2¤t=y0;0t0;0y0);%inlineMÀ[t;y]=ode45(odefun;[0;4];1);n=length(t);e=sqrt(sum((sqrt(1+2¤t)¡y):^2)=n);[n;e]ans=45:00000:0002À[t;y]=ode23(odefun;[0;4];1);n=length(t)