问题
This is my first attempt to write anything in matlab, so please, be patient.
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
where G is the solution of the following ODE:
where G(0) = G'(0) =0, s
is a constant, and
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);
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);
but is says
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);
Now, I am not sure if this definition of wG
is correct at all and if there are not any other definitions.
Appendix: nonlinearGreen(N)
is defined as follows:
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
and nonlinearnonhom
is defined as follows:
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:
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.
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);
It means that the function laplace
can't have arguments of type double
.
The problem is that your t
is a vector of double
. Another mistake is that s
is not defined in your code.
According to Matlab documentation of laplace, all arguments are of type symbolic
.
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);
I have no error after that.
来源:https://stackoverflow.com/questions/53530572/error-while-evaluating-the-function-convolution