简体   繁体   中英

How do I solve a second order differential equation using Octave?

I am completely new to Octave and I am trying to solve the equations below for my project. I was unable to find any straightforward guide to solving the differential equations. Could someone demonstrate how to solve it? Your help is much appreciated!

I am trying to plot a graph of h over time for the equations with a given initial h, miu, r, theta, g, L, and derivatives of h and theta wrt t. Is this possible? And if so, how?

The two equations mentioned

I tried to type the equations into Octave with the given conditions, but there seems to be an error that I am unable to identify.

I am also extremely new to coding, but I need this to complete my project

Whatever is the numerical software you will use, Octave or another one (that does not formal calculation), the first step is to transform your system or N coupled Ordinary Differential Equations (ODEs) of order p into a system of p*N coupled ODEs of order 1 .

This is always done by setting intermediate derivatives as new variables. For your system, then在此处输入图像描述

will become

在此处输入图像描述

Then, with Octave, and as explained in doc lsode you define a function say Xdot = dsys(X) , that codes this system. X is the vector [h, theta, H, J] , and Xdot is the returned vector of their respective derivatives, as defined by the right hand expressions of the system of first order ODEs.

So, the 2 first elements of Xdot will be trivial, just Xdot=[X(3) X(4)...] .

Of course, dsys() must also use the parameters M, g, m, µ, L , and r . As far as i understand, they can't be passed as additional arguments to dsys() . So you must defined them before calling lsode .

For initial states, you must define the vector X0=[h0, theta0, H0, J0] of known initial values.

The vector of increasing times >= 0 to which you want to compute and get the values of X must then be defined. For instance, t = 0:100 . 0 must be the first element of t .

Finally, call Xt = lsode(@dsys, X0, t) . After that you should get

  • Xt(:,1) are the values of h(t)
  • Xt(:,2) are the values of theta(t)
  • Xt(:,3) are the values of H(t)=(dh/dt)(t)
  • Xt(:,4) are the values of J(t)=(dtheta/dt)(t)

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