[MATLAB] Numerical calculation of differential equations and ODE45 parameters

Source: Internet
Author: User
Tags function prototype
[MATLAB] numerical calculation of differential equation sets

We use the ode45 function When we cannot use dsolve to do symbolic solving.

The function prototype is

[T,y] = Ode45 (odefun,tspan,y0) Example
[t,y] = Ode45 (odefun,tspan,y0,options) Example
[T,y,te,ye,ie] = Ode45 ( odefun,tspan,y0,options)
sol = ode45 (___)

Write the function file first. m as the first parameter of the Ode45 Odefun

Function y = Fun (t,x,flag,k)
%flag are a [] to mark the args

%---------------
%some global setting
lamda=1 ;
%---------------
    y=[x (2) *k,lamda*x (2) * (1-x (1)-X (2))-k*x (2)] ';

End

T is the default argument, and X is a vector of dependent variables. The return value is the first derivative of the corresponding dependent variable vector, or we can write

Function y = Fun (t,x,flag,k)
%flag are a [] to mark the args
%---------------
%some global setting
LAMD a=1;
%---------------
    Y=zero (2,1)
    y (1) =x (2) *k;
    Y (2) =lamda*x (2) * (1-x (1)-X (2))-k*x (2);
End

Then write Ode45

[T,x]=ode45 (' fun ', tspan,[0,x0],[],each);

Tspan for [0:10] argument range
The third parameter is the initial value vector
The fourth parameter empty array is used as flag to distinguish the parameters of the incoming fun and the parameters required for Ode45

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.