简体   繁体   English

在八度音阶中定义微分方程

[英]Defining a Differential Equation in Octave

I am attempting to use Octave to solve for a differential equation using Euler's method. 我正在尝试使用Octave使用欧拉方法求解微分方程。

The Euler method was given to me (and is correct), which works for the given Initial Value Problem, Euler方法是给我的(并且是正确的),它适用于给定的初值问题,

y*y'' + (y')^2 + 1 = 0; y(1) = 1;

That initial value problem is defined in the following Octave function: 该初始值问题在以下Octave函数中定义:

function [YDOT] = f(t, Y)

YDOT(1) = Y(2);
YDOT(2) = -(1 + Y(2)^2)/Y(1);

The question I have is about this function definition. 我有关于此函数定义的问题。 Why is YDOT(1) != 1? 为什么YDOT(1)!= 1? What is Y(2)? 什么是Y(2)? I have not found any documentation on the definition of a function using function [YDOT] instead of simply function YDOT, and I would appreciate any clarification on what the Octave code is doing. 我没有找到有关使用函数[YDOT]而不是简单地使用函数YDOT的函数定义的文档,并且希望对Octave代码的功能进行任何澄清。

First things first: You have a (non linear) differential equation of order two which will require you to have two initial conditions. 首先,您需要:具有一个二阶(非线性)微分方程,这将需要两个初始条件。 Thus the given information from above is not enough. 因此,从上面给出的信息是不够的。

The following is defined for further explanations: A==B means A is identical to B ; 为进一步解释定义了以下内容: A==B表示A is identical to B A=>B means B follows from A . A=>B表示B follows from A

It seems you are mixing a few things. 看来您正在混合一些东西。 The guy who gave you the files rewrote the equation in the following way: 给您文件的那个人用以下方式重写了等式:

y*y'' + (y')^2 + 1 = 0; y(1) = 1; | (I) y := y1 & (II) y' := y2

(I) & (II)=>(III): y' = y2 = y1' | y2==Y(2) & y1'==YDOT(1) 

Ocatve is "matrix/vector oriented" so we are writing everything in vectors or matrices. Ocatve是“面向矩阵/向量的”,因此我们将所有内容都写成向量或矩阵。 Rather writing y1=alpha and y2=beta we are writing y=[alpha; beta] 而不是写y1=alphay2=beta我们写y=[alpha; beta] y=[alpha; beta] where y(1)==y1=alpha and y(2)==y2=beta . y=[alpha; beta] ,其中y(1)==y1=alphay(2)==y2=beta You will soon realize the tremendous advantage of using especially this mathematical formalization for ALL of your problems. 您很快就会意识到,尤其是对所有问题都使用这种数学形式化的巨大优势。

(III) & f(t,Y)=>(IV): y2' == YDOT(2) = y'' = (-1 -(y')^2) / y

Now recall what is y' and y from the definitions in (I) and (II) ! 现在从(I)(II)的定义中回顾y'y是什么!

y' = y2 == Y(2) & y = y1 == Y(1)

So we can rewrite equation (IV) 这样我们可以重写方程式(IV)

(IV): y2' == YDOT(2) = (-1 -(y')^2) / y == -(1 + Y(2)^2)/Y(1)

So from equation (III) and (IV) we can derive what you already know: 因此,根据方程式(III)(IV)我们可以得出您已经知道的信息:

YDOT(1) = Y(2)
YDOT(2) = -(1 + Y(2)^2)/Y(1)

These equations are passed to the solver. 这些方程式传递给求解器。 Differential equations of all types are solved numerically by retrieving the "next" value in a near neighborhood to some "previously known" value. 通过检索附近某个“先前已知”值的“ next”值,可以数值求解所有类型的微分方程。 (The step size inside this neighborhood is one of the key questions when writing solvers!) So your solver uses your initial condition Y(1)==y(1)=1 to make the next step and calculate the "next" value. (此邻域内的步长是编写求解器时的关键问题之一!)因此,您的求解器将使用初始条件Y(1)==y(1)=1进行下一步并计算“下一个”值。 So right at the start YDOT(1)=Y(2)==y(2) but you didn't tell us this value! 所以YDOT(1)=Y(2)==y(2)开始时YDOT(1)=Y(2)==y(2)但是您没有告诉我们这个值! But from then on YDOT(1) is varied by the solver in dependency to the function shape to solve your problem and give you ONE unique y(t) solution. 但是从那时起,求解器根据函数形状改变YDOT(1)来解决您的问题并提供一个唯一的y(t)解决方案。

It seems you are using Octave for the first time so let's make a last comment on function [YDOT] = f(t, Y) . 似乎您是第一次使用Octave,因此让我们对function [YDOT] = f(t, Y)进行最后评论。 In general a function is defined in this way: 通常,函数是通过以下方式定义的:

function[retVal1, retVal2, ...] = myArbitraryName(arg1, arg2, ...)

Where retVal is the return value or output and arg is the argument or input . 其中retValreturn valueoutputargargumentinput

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

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