简体   繁体   English

八度 ODE 的 plot 系统

[英]plot system of ODE in Octave

I have a matrix of ODE which I want to solve and plot.我有一个要解决的 ODE 矩阵和 plot。

x
x = (sym 2×1 matrix)

  ⎡            -331⋅π⋅t                 -61⋅π⋅t  ⎤
  ⎢            ─────────                ──────── ⎥
  ⎢               2299               2   10835   ⎥
  ⎢ 689986800⋅ℯ            89076600⋅π ⋅ℯ         ⎥
  ⎢ ──────────────────── + ───────────────────── ⎥
  ⎢       1307333                 12173551       ⎥
  ⎢                                              ⎥
  ⎢             -331⋅π⋅t                 -61⋅π⋅t ⎥
  ⎢             ─────────                ────────⎥
  ⎢                2299                   10835  ⎥
  ⎢  206492400⋅ℯ            139429800⋅π⋅ℯ        ⎥
  ⎢- ──────────────────── + ─────────────────────⎥

How can I plot both x(1) and x(2) in Octave?如何在 Octave 中同时使用x(1)x(2) plot?

Code for reproduction:复制代码:

pkg load symbolic;
A = [-0.4, 0.4; 0.05, -0.07];
[M, Lambda] = eig(A);
t = sym('t');
Phi = M * expm(Lambda*t)*inv(M);
x = Phi * [600; 0]

There are two main approaches.有两种主要方法。

Have a look at the documentation for @sym/function_handle and @sym/eval .查看@sym/function_handle@sym/eval的文档。

Assuming you have created on your workspace the following domain:假设您已在工作区中创建了以下域:

t = -10:0.1:10;

Then here are examples of each approach:然后这里是每种方法的示例:

  • The function handle approach: function手柄方法:

     f1 = function_handle( x(1) ); f2 = function_handle( x(2) ); plot( t, f1(t) ); hold on; plot( t, f2(t) ); hold off
  • The eval approach:评估方法:

     plot( t, eval( x(1) ) ); hold on plot( t, eval( x(2) ) ); hold off

The function_handle approach converts your expression to a regular numerical function, that you can pass arguments to (in this case, a valid 't'). function_handle 方法将您的表达式转换为常规数值 function,您可以将 arguments 传递给(在这种情况下,一个有效的 't')。

The eval approach detects that your symbolic expression contains the variable "t", looks for "t" on your workspace, substitutes whatever's on your workspace into the symbolic expression, and then numerically evaluates the result. eval 方法检测到您的符号表达式包含变量“t”,在您的工作空间中查找“t”,将工作空间中的任何内容替换为符号表达式,然后对结果进行数值计算。

Out of the two, the function handle approach is probably safest:)在这两者中,function 手柄方法可能是最安全的:)

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

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