评估函数卷积时出错 [英] Error while evaluating the function convolution

查看:102
本文介绍了评估函数卷积时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my first attempt to write anything in matlab, so please, be patient.

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

I am trying to evaluate the solution of the following ODE: w'' + N(w, w') = f(t) with the Cauchy conditions w(0) = w'(0) = 0. Here N is a given nonlinear function, f is a given source. I also need the function

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

where G is the solution of the following ODE:

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

where G(0) = G'(0) =0, s is a constant, and

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

My try is as follows: I define N, f, w and G:

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.为此,我使用正拉普拉斯变换和逆拉普拉斯变换如下:

This part is ok. I can plot both w and G: both seems to be correct. Now, I want to evaluate wG. For that purpose, I use the direct and inverse Laplace transforms as follows:

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的定义是否正确以及是否没有其他定义.

Now, I am not sure if this definition of wG is correct at all and if there are not any other definitions.

附录: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 文档,并将函数重写为象征性的.

You keep mixing different kind of types and it's not a good idea. I suggest you keep with symbolic all the way if you want to use the laplace function. When you define N and f with @(arobase) as function handles and not symbolic expressions as you might want to do. I suggest you have a look at symbolic documentation and rewrite your functions as symbolic.

然后,错误消息很清楚.

Then, the error message is pretty clear.

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

这意味着函数laplace不能具有类型为double的参数.

It means that the function laplace can't have arguments of type double.

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

The problem is that your t is a vector of double. Another mistake is that s is not defined in your code.

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

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

You can try to manually specify symbolic s and t.

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

那之后我没有错误.

这篇关于评估函数卷积时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆