octave - Octave - 带有 lsode 的微分方程组
问题描述
这是我的问题。由于下面的两个函数,我正在尝试求解一个由两个微分方程组成的系统。给我带来麻烦的代码部分是变量“rho”。“rho”是一个函数,它的值是从文件中给出的,我试图把它放入变量 rho。
function [xdot]=f2(x,t)
# Parameters of the equations
t=[1:1:35926];
x = dlmread('data_txt.txt');
rho=x(:,4);
beta = 0.68*10^-2;
g = 1.5;
l = 1.6;
# Definition of the system of 2 ODE's :
xdot(1) = ((rho-beta)/g)*x(1) + l*x(2);
xdot(2) = (beta/g)*x(1)-l*x(2);
endfunction
.
# Initial conditions for the two variables :
x0 = [0;1];
# Definition of the time-vector -> (initial time,temporal mesh,final time) :
t = linspace (1, 10, 10000);
# Resolution with the lsode routine :
x = lsode ("f2", x0, t);
# Plot of the two curves :
plot (t,x);
当我运行我的代码时,我收到以下错误:
>> resolution_effective2
error: f2: A(I) = X: X must have the same size as I
error: called from
f2 at line 34 column 9
resolution_effective2 at line 8 column 3
error: lsode: evaluation of user-supplied function failed
error: called from
resolution_effective2 at line 8 column 3
error: lsode: inconsistent sizes for state and derivative vectors
error: called from
resolution_effective2 at line 8 column 3
我知道我的错误来自某些变量之间的大小不匹配,但我已经找了好几天了,但我没有看到。有人可以尝试给我一个有效的更正并向我解释吗?谢谢
解决方案
错误可能来自您的函数f2
。它的第一个参数应该具有与的初始条件x
相同的维度x0
。x0
x
在您的情况下,无论您打算成为第一个参数,f2
都将被忽略,因为在您的函数中,您这样做x = dlmread('data_txt.txt');
似乎是一个错误。
那么,xdot(1) = ((rho-beta)/g)*x(1) + l*x(2);
将是一个问题,因为rho
它是一个向量。
您需要检查 和 的x
尺寸rho
。
推荐阅读
- c# - C#语法超越我,初学者
- go - 在 struct -> []byte -> gob -> gzip -> IO -> gzip -> gob -> []byte -> struct 之后存储到磁盘
- apache - 使用 APACHE REWRITE 强制特定目录为 HTTPS (.htaccess)
- java - 没有明确提及 JOIN 的 JPA 查询
- javascript - 它可以用 ReactJS 处理 JSON 文件吗?
- python-3.x - 创建一个时间数组,以秒为单位,从每个小时的读数开始的月份开始
- python - 我的 kmeans 聚类似乎效果不佳
- ios - 选择器在 Swift 中有返回值吗?
- javascript - 使用 async/await 从回调中返回对象
- java - 使用 java spring-boot 应用程序从 BigQuery 表中读取数据