Hello, I have a problem trying to integrate. I have only been using MatLab for about 3 months now, very new to it.
This is the equation I am trying to integrate x(t) = (-0.75)^t *(u(t) - u(t-8)) I had to use the freqz function first, and now it's asking me to compare freqz to manually doing the Fourier Transform, which basically states taking the integral from negative infinity to positive infinity of x(t) * e^(-2pi*f*t) dt
I am kinda skipping a step and integrating from 0 to 8, it's 0 everywhere else (however if possible I'd like to know how to integrate from negative infinity to positive infinity). Anyways, that's basically what I'm trying to do, integrate, (-0.75)^t from 0 to 8. This is what I have currently but I keep getting errors. Should I be using 'integral' or 'int'?
clear all; close all;
t = [0:.01:10];
j = sqrt(-1);
syms f;
u1 = heaviside(t);
u2 = heaviside(t - 8);
x = ((-0.75).^t).*(u1 - u2);
y = ((-0.75).^t) .* exp(-2*pi.*j.*t.*f);
X = int(y, 0, 8);
plot(X);

 採用された回答

Star Strider
Star Strider 2016 年 3 月 14 日

0 投票

If your function is defined over ‘t’ from 0 to 8, integrate over that time. I’m not quite certain what you’re doing, so you’ll likely have to change this code to fit, but some revision of it should work:
syms f t
u1 = heaviside(t);
u2 = heaviside(t - 8);
x = ((-0.75).^t).*(u1 - u2);
y = x .* exp(-2*pi.*1i.*t.*f);
X = int(y, t, 0, 8);
X = rewrite(X, 'sincos');
X = simplify(X, 'steps',10)
figure(1)
ezplot(abs(X), [0 2*pi])

4 件のコメント

Maty Blanc
Maty Blanc 2016 年 3 月 14 日
編集済み: Maty Blanc 2016 年 3 月 14 日
What is the difference between how you defined t and how I did? I used t = [0:.01:8], what does the syms do?
EDIT: This is what I'm looking for, thank you. I'd just like to go over the code so I can fully understand it. When I used syms, it was only because I saw it done online, no idea what it does..
Star Strider
Star Strider 2016 年 3 月 14 日
My pleasure.
The Symbolic Math Toolbox does not use time vectors to do its calculations (unless you want it to, and then you have to define them after the syms call). Here, you are doing a purely symbolic calculation, so a time vector is not necessary. Simply define the limits of integration in terms of the time you want, here 0 and 8. Also, since you have both ‘t’ and ‘f’ in your integrand, you have to tell the int function the variable you want it to integrate with respect to.
Other than that, your code was correct. I added the rewrite and simplify calls to produce a more readable final result, and added the ezplot call because you indicated you wanted to plot it. Change the range of the independent variable ‘f’ (now [0 2*pi]) to the range you want.
Maty Blanc
Maty Blanc 2016 年 3 月 14 日
編集済み: Maty Blanc 2016 年 3 月 14 日
I see, so having t defined 0:.01:8 and then integrating from 0 to 8 was redundant? And based on MatLab language, I should not define t, just keep it as a variable? Last question on the ezplot, I looked it up and they said not recommended, why can't you use the function plot? I tried and I got an error, why won't it take it? Is it because it's a syms variable?
Star Strider
Star Strider 2016 年 3 月 14 日
‘...so having t defined 0:.01:8 and then integrating from 0 to 8 was redundant?’
The vector was unnecessary with the int function. With trapz or cumtrapz it would have been necessary, but those numeric integrations would not have given you the analytic result you wanted.
‘I should not define t, just keep it as a variable?’
Here, in the context of a symbolic integration, correct.
The ezplot function is obsolete (or ‘deprecated’ in favour of fplot) as of R2016a. I used it here because I don’t know what version you’re using, and it’s been part of MATLAB for as long as I can remember. You certainly can use plot, but you have to provide two vectors to it, one representing the independent variable and one representing the dependent variable. If you want to use plot with your function, you would have to create an anonymous function representation from your ‘X’ function. The easiest way to do that is to use the Symbolic Toolbox matlabFunction function. You can avoid creating a distinct, separate variable for your dependent variable by doing the function call in the plot call itself.
For example:
syms f t
u1 = heaviside(t);
u2 = heaviside(t - 8);
x = ((-0.75).^t).*(u1 - u2);
y = x .* exp(-2*pi.*1i.*t.*f);
X = int(y, t, 0, 8);
X = rewrite(X, 'sincos');
X = simplify(X, 'steps',10)
Xfcn = matlabFunction(X)
f = linspace(0, 5*pi);
figure(2)
plot(f, real(Xfcn(f)), f, imag(Xfcn(f)))
grid

サインインしてコメントする。

その他の回答 (1 件)

DHARUN M
DHARUN M 2020 年 5 月 18 日

0 投票

x^5+3cos(4x)-4x^3+2x^2+9x/tan(x)^2-sec(x^2-2x+3)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2016 年 3 月 14 日

回答済み:

2020 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by