简体   繁体   中英

How to solve a coupled nonlinear first order differential equation?

I have a problem in the form of 2 equations and known initial conditions. The equations are:

dx/dt = (-a1*sin(y) + a2 + a3*sin(yx)) / ((dy/dt)*a4*cos(yx))

dy/dt = (a1*sin(x) -a5 + a6*x + a7*sin(yx)) / ((dx/dt)*a8*cos(yx))

where a1 to a8 are variables.

I am trying to plot x vs t and y vs t on MATLAB, but I am not sure how to solve this numerically or analytically. Any help would be appreciated!!

The ODE of your problem cannot be written as d y /dt=f(t, y ) nor M(t, y )d y /dt=f(t, y ) . That means it is a Differential Algebraic Equation which has to be solved numerically in the form:

f(t, y , d y /dt)=0

In matlab this can be done with the command ode15i .

Therefore, the first step is to write the function in a proper way, in this case, one option is:

function f = cp_ode(t,y,yp,a)
    f1 = (-a(1)*sin(y(2))+a(2)+a(3)*sin(y(2)-y(1)))/yp(2)*a(4)*cos(y(2)-y(1)) - yp(1);
    f2 = (a(1)*sin(y(1))-a(5)+a(6)*y(1)+a(7)*sin(y(2)-y(1)))/yp(1)*a(8)*cos(y(2)-y(1)) - yp(2);
    f = [f1 ; f2] ; 
end

Then, the initial conditions and integration timespan can be set in order to call ode15i :

tspan = [0 10];
y0 = [1; 1] ; 
yp0 = fsolve(@(yp)cp_ode(0,y0,yp,a),<yp0_guess>);
a = ones(1,8) ;
[t,y] = ode15i(@(t,y,yp)cp_ode(t,y,yp,a), tspan, y0, yp0);

It has to be noted that the initial conditions t, y , yp should fulfill the equation f(t, y , yp )=0 . Here an fsolve is used to satisfy this condition.

The use of annonymus functions is to define the function with the parameters as inputs and then execute the ODE solver having defined the parameters in the main code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM