1
votes

I want to calculate this integration symbolically in Matlab:

syms z mu t k

f(z,mu) = exp(-(z-mu)^2);

a(t,k) = exp(-t/k);

int(f(z,mu)*a(t-z,k),z,[0,t])

But Matlab can't evaluate the result. Mathematica can easily compute this integral. I cannot send the terms from Mathematica to Matlab by MatLink so I decided to do everything in Matlab. Is there any way to compute this integral? I don't want to do this numerically because this would be slower than integrating symbolically and then giving it inputs.

Edit

The given answer works for the above example but it doesn't work for this one:

syms z mu t k del

f(z,mu) = exp(-((z-mu)/del)^2);

a(t,k) = exp(-t/k);

int(f(z,mu)*a(t-z,k),z,[0,t])

I divided (z-mu) in the exponential function by the symbolic variable del.

1
Is that integral equivalent to a Laplace transform? If so, maybe you can compute it via a Laplace transform function in Matlab (I don't know the name of it) or look it up in a table. - Robert Dodier
the upper bound in Laplace transform in infinity, but here it is variable t. - MOON
Good point. Actually, it is a convolution, isn't it? In that case you could use the identity L(f*g) = L(f) L(g) where f*g is the convolution of f and g and L is the Laplace transform. - Robert Dodier
Are all of of your symbolic variables potentially complex (the default) or do you know if any/all are real? Do you know if any of the variables are restricted to particular domains, e.g., are any > 0 or >= 0 or some other set of bounds? When doing symbolic math in Matlab you need to take advantage of assumptions in order to simply and help solve your problems. - horchler

1 Answers

4
votes

Simplify the expression first, then it works

clear all
syms z mu t k
f(z,mu) = exp(-(z-mu)^2);
a(t,k) = exp(-t/k);
int(simplify(f(z,mu)*a(t-z,k)),z,[0,t])

ans

-(pi^(1/2)*exp(-t/k)*exp(1/(4*k^2))*exp(mu/k)*
           (erf(mu - t + 1/(2*k)) - erf(mu + 1/(2*k))))/2

Matlab 2015a, windows 7