super1ha1
super1ha1

Reputation: 629

Symbolic functions: Input arguments must be 'double'

I want to calculate the integral of the following function using int in MATLAB. I tried the following way, but it always shows the error Input arguments must be 'double':

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

or

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

or

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

My function definitions are:

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

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

Upvotes: 1

Views: 1055

Answers (1)

Robert Seifert
Robert Seifert

Reputation: 25232

You need to declare your functions to be symbolic:

syms square
syms step2

Why step2? Because step is an already defined function of a common toolbox.


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)

Upvotes: 3

Related Questions