评估函数卷积时出错

时间:2018-11-29 01:29:42

标签: matlab symbolic-math

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

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

enter image description here

其中G是以下ODE的解决方案:

enter image description here

其中G(0)= G'(0)= 0,s是一个常数,并且

enter image description here

我的尝试如下:我定义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

1 个答案:

答案 0 :(得分:2)

您不断混合使用不同类型的类型,这不是一个好主意。如果您想使用laplace函数,建议您始终使用符号。当您将N(arobase)的f@定义为function handles而不是您可能想要的symbolic expressions时。我建议您看看symbolic文档,并以符号形式重写函数。

然后,错误消息很清楚。

  

类型为'double'的输入参数的未定义函数'laplace'。
  主线错误(第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);

那之后我没有错误。

相关问题