评估函数卷积时出错

Error while evaluating the function convolution

这是我第一次尝试在 matlab 中编写任何东西,所以请耐心等待。

我正在尝试计算以下 ODE 的解:w'' + N(w, w') = f(t),柯西条件 w(0) = w'(0) = 0。这里N是给定的非线性函数,f是给定的源。我还需要函数

其中 G 是以下 ODE 的解:

其中G(0) = G'(0) =0,s为常数,

我的尝试如下:我定义了NfwG:

k = 1000;
N = @(g1,g2) g1^2 + sin(g2);
f = @(t) 0.5 * (1 + tanh(k * t));

t = linspace(0, 10, 100);
w = nonlinearnonhom(N, f);
G = nonlinearGreen(N);

这部分还可以。我可以绘制 wG:两者似乎都是正确的。现在,我要评估wG。为此,我使用直接和逆拉普拉斯变换如下:

wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);

但是说

Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);

现在,我不确定 wG 的这个定义是否完全正确,是否没有任何其他定义。

附录: nonlinearGreen(N)定义如下:

function G = nonlinearGreen(N)

eps = .0001;
del = @(t)[1/(eps * pi) * exp( -t^2/eps^2)];

eqGreen = @(t, g)[g(2); - N(g(1),g(2)) + del(t)];
tspan = [0, 100];
Cc = [0, 0];
solGreen = ode45(eqGreen, tspan, Cc);
t = linspace(0, 10, 1000);
G = deval(solGreen, t, 1);

end

nonlinearnonhom定义如下:

function w = nonlinearnonhom(N, f)

eqnonhom = @(t, g)[g(2); - N(g(1),g(2)) + f(t)];
tspan = [0, 100];
Cc = [0, 0];
solnonhom = ode45(eqnonhom, tspan, Cc);
t = linspace(0, 10, 100);
w = deval(solnonhom, t, 1);

end

你总是混合不同种类的类型,这不是一个好主意。如果你想使用 laplace 函数,我建议你一直使用符号。当您将 Nf@(arobase) 定义为 function handles 而不是您可能想要的 symbolic expressions 时。我建议您查看 symbolic 文档并将您的函数重写为符号函数。

那么,错误信息就很清楚了。

Undefined function 'laplace' for input arguments of type 'double'.
Error in main (line 13)
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);

表示函数laplace不能有double类型的参数。

问题是你的 tdouble 的向量。另一个错误是 s 未在您的代码中定义。

根据 laplace 的 Matlab 文档,所有参数都是 symbolic.

类型

您可以尝试手动指定符号 st

% t = linspace(0, 10, 100); % This is wrong
syms s t
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);

之后我没有错误。