How do I integrate this equation?

4 visualizaciones (últimos 30 días)
Maty Blanc
Maty Blanc el 14 de Mzo. de 2016
Respondida: DHARUN M el 18 de Mayo de 2020
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);

Respuesta aceptada

Star Strider
Star Strider el 14 de Mzo. de 2016
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 comentarios
Maty Blanc
Maty Blanc el 14 de Mzo. de 2016
Editada: Maty Blanc el 14 de Mzo. de 2016
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 el 14 de Mzo. de 2016
‘...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

Iniciar sesión para comentar.

Más respuestas (1)

DHARUN M
DHARUN M el 18 de Mayo de 2020
x^5+3cos(4x)-4x^3+2x^2+9x/tan(x)^2-sec(x^2-2x+3)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by