Reputation: 135
I have an array of numbers and I want to integrate each column in the array seperatley, and in the end get back an array of numbers after the integration.
I tried "trapz" function but I get a single value, how can i do what I want above?
Here's my code:
t=-1:0.001:1;
x1=100*sinc(100*t);
x2= 100*(sinc(100*t)).^2;
W= -2000*pi:2*pi:2000*pi;
T=-1:0.001:1;
u=x1.*exp(-1i.*W.*t);
v=x2.*exp(-1i.*W.*t);
X11= trapz(t,u);
X22= trapz(t,v);
Thanks in advance.
Upvotes: 0
Views: 403
Reputation: 32920
If I'm following you correctly, you need u
and v
to be matrices. For that purpose, you have to resolve two issues in your code:
the ω⋅t
product should be a matrix rather than a vector. For that purpose, you need to use matrix multiplication W.' * t
(note the added transpose!) and not element-wise multiplication (.*
). This produces all the necessary combinations of ω⋅t
required for the transform.
In a similar fashion, you need to multiply x
by exp(-iωt)
column-wise. Use bsxfun
instead of the element-wise multiplication, like so:
u = bsxfun(@times, x1(:), exp(-i * W.' * t));
The same applies for v
.
Since you're using the same exp(-i * W.' * t)
both for u
and for v
, I suggest computing it once and storing it in a variable:
E = exp(-i * W' * t);
u = bsxfun(@times, x1(:), E);
v = bsxfun(@times, x2(:), E);
Following this fix, trapz
should produce the desired results now, i.e. X11
and X12
should really be the Fourier Transform applied on x1
and x2
, respectively.
Upvotes: 1