符号函数:输入参数必须为'double'

时间:2016-04-14 05:48:28

标签: matlab symbolic-math

我想在MATLAB中使用int计算以下函数的积分。我尝试了以下方法,但它始终显示错误Input arguments must be 'double'

syms x
int(exp(x) .* 1000 .* square(1000 .* (x -1)))

syms x
int(exp(x) * 1000 * square(1000 * (x -1)), x, -1000, 1000)

syms x
int(exp(x) * 1000 * square(1000 * (x -1)), x, -1000.0, 1000.0)

我的功能定义是:

function y = step(t)
y = (1 + sign(t))/2;
end

function y = square(t)
y = step(t + 0.5) - step(t - 0.5);
end

1 个答案:

答案 0 :(得分:3)

您需要将您的函数声明为符号:

syms square
syms step2

为什么step2?因为step是已定义的常用工具箱函数。

MWE

function test

syms x z
syms square
syms step2

z1 = int(exp(x) .* 1000 .* square(1000 .* (x -1)))
z2 = int(exp(x) * 1000 * square(1000 * (x -1)), x, -1000, 1000)
z3 = int(exp(x) * 1000 * square(1000 * (x -1)), x, -1000.0, 1000.0)

end

function y=step2(t)
y = (1 + sign(t))/2;
end

function y = square(t)
y = step2(t + 0.5) - step2(t - 0.5);
end
z1 = 500*exp(x)*(sign(1000*x - 1999/2) - sign(1000*x - 2001/2))
z2 = 1000*exp(1999/2000)*(exp(1/1000) - 1)
z3 = 1000*exp(1999/2000)*(exp(1/1000) - 1)