作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
A
是 (N-1)X(N-1)
的矩阵, f
定义为:f(x,t)=1000*sqrt(|1-t|)
, μ=1
, u(x,0)=1000x(1-x)(1+(3/2)x^3)
, L=1
和 u(0,t)=u(1,t)=0
所有 t
, h
是 1/N
( N
区间的分区数)。 最佳答案
我不是专家,您遗漏了一些信息(例如 x 的特定性质)。
但是,作为如何“运行” lsode 函数的示例,下面是一个示例,它做出以下假设:
N = 4; % number of bins
mu = 1;
h = 1 / N;
A_matrix = rand( N - 1, N - 1 );
t_rvector = [0 : 20].';
x_cvector = linspace( 0, 1, N + 1 ).'; % N+1 edges, including outer ones
x_cvector = x_cvector(2 : end - 1); % discard outer edges, keep inner only.
% Create f(t) as defined in the question, but vectorised w.r.t. x
% (i.e. outputting an N-1 element vector that can be added to a corresponding u vector)
f_function = @(t) 1000 .* sqrt( abs( 1 - t ) ) .* ones( size( x_cvector ) );
% Create a u0 vector (of N-1 elements, corresponding to inner edges on the bar)
u0_cvector = 1000 .* x_cvector .* (1 - x_cvector) .* (1 + (3 / 2) .* x_cvector .^ 3);
% Create a 'wrapper' function of the form expected by `lsode`
ode_function = @(u_cvector, t) -mu ./ (h .^ 2) .* A_matrix * u_cvector + f_function(t);
% Run `lsode`
[u_matrix, ISTATE, MSG] = lsode( ode_function, u0_cvector, t_rvector )
% Pad u_matrix with 0s on left and right, corresponding to x=0 and x=1 values
TimePoints = length( t_rvector );
ZeroColumn = zeros( TimePoints, 1 );
u_matrix = [ ZeroColumn, u_matrix, ZeroColumn ];
% Plot the curves (when plotting a matrix, each column is treated as a separate plot), therefore if you want to plot along the 'components' of u (corresponding to positions in $
plot ( u_matrix.' );
这可能与您的问题不同,但上面的代码按预期运行,因此希望它可以帮助您作为起点。
u
矢量传递到
lsode
功能需要采用“列”形式。 (时间点列表可以是列或行,无关紧要)。
关于OCTAVE 求解常微分方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64731771/
我是一名优秀的程序员,十分优秀!