Info

This question is closed. Reopen it to edit or answer.

Problem trying to integrate a function

1 view (last 30 days)
Hyesun Cha
Hyesun Cha on 26 Apr 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
function rect = t1(x)
if x < 1 && x > -1
rect = 1;
else
rect = 0;
end
this was my function in a separate script file.
syms e x
pattern1 = t1(x);
ftpattern1 = int(pattern1*exp(-2*i*pi*e*x),x,-inf,inf);
Matlab keeps on giving a message that says I have an error in t1 if x < 1 && x > -1. I think I'm not allowed to give logical expression to symbols such as x... Any suggestions?

Answers (1)

Star Strider
Star Strider on 26 Apr 2015
You’re close, but you’re not defining it correctly.
The definition of a pulse in the Symbolic Math context:
syms x w t T
rect = heaviside(x+1) - heaviside(x-1);
figure(1)
ezplot(rect, [-2 2]) % Display Function
grid
However the correct way to define it in terms of calculating its Fourier transform is to define it as 1 between -T and +T:
syms x w t T
ftpattern1 = int(1*exp(-j*w*t), t, -T, T)
produces:
ftpattern1 =
(2*sin(T*w))/w
Here, you can define T=1, and plotting it:
ftpattern1 = subs(ftpattern1, T, 1)
figure(2)
ezplot(ftpattern1, [-10*pi, 10*pi])
grid
This is the expected result.

This question is closed.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!