How do I integrate this equation?

조회 수: 4 (최근 30일)
Maty Blanc
Maty Blanc 2016년 3월 14일
답변: DHARUN M 2020년 5월 18일
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일
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일
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일
x^5+3cos(4x)-4x^3+2x^2+9x/tan(x)^2-sec(x^2-2x+3)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by