简体   繁体   English

如何使用 Octave 求解二阶微分方程?

[英]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.我是 Octave 的新手,我正在尝试为我的项目求解以下方程式。 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.我正在尝试 plot 对于具有给定初始 h、miu、r、theta、g、L 以及 h 和 theta wrt t 的导数的方程,h 随时间变化的图表。 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.我尝试在给定条件下将方程式输入 Octave,但似乎存在我无法识别的错误。

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 .无论您将使用什么数值软件,Octave 或其他软件(不进行形式计算),第一步是将您的系统或 p 阶 N 耦合常微分方程 (ODE) 转换为 p*N 耦合 ODE 系统订单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.然后,使用 Octave,如doc lsode中所述,您定义了一个 function say Xdot = dsys(X) ,它对该系统进行编码。 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. X是向量[h, theta, H, J]Xdot是它们各自导数的返回向量,如一阶 ODE 系统的右侧表达式所定义。

So, the 2 first elements of Xdot will be trivial, just Xdot=[X(3) X(4)...] .因此, Xdot的前 2 个元素将是微不足道的,只是Xdot=[X(3) X(4)...]

Of course, dsys() must also use the parameters M, g, m, µ, L , and r .当然, dsys()还必须使用参数M, g, m, µ, Lr As far as i understand, they can't be passed as additional arguments to dsys() .据我了解,它们不能作为额外的 arguments 传递给dsys() So you must defined them before calling lsode .所以你必须在调用lsode之前定义它们。

For initial states, you must define the vector X0=[h0, theta0, H0, J0] of known initial values.对于初始状态,您必须定义已知初始值的向量X0=[h0, theta0, H0, J0]

The vector of increasing times >= 0 to which you want to compute and get the values of X must then be defined.然后必须定义要计算并获取 X 值的递增时间向量 >= 0。 For instance, t = 0:100 .例如, t = 0:100 0 must be the first element of t . 0 必须是t的第一个元素。

Finally, call Xt = lsode(@dsys, X0, t) .最后,调用Xt = lsode(@dsys, X0, t) After that you should get之后你应该得到

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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