フィルターのクリア

How to numerically integrate two vectors in 2012a

2 ビュー (過去 30 日間)
Chris
Chris 2012 年 12 月 15 日
Bold = edit I've been trying to integrate two vectors t & a each with approx 100 values. I need to integrate c(T) = int a(t) dt between T and 0.
----edit----
I have two vectors a, and t. I need a vector answer c. each vector has aprox 100 values, and i need c to have this amount of answers too
c(T) = integral of a(b) with respect to t (dt), between T and 0. (T>0)
And i need c(T) to be in vector form. I've tried trapz, but this only gives me a single value. And i cant use the 'quad', or 'intergral' function, as i do not have an imput function. (Or cannot figure out how to create a function for this that works).
I am getting my a, and t, values from another function. Each t value corresponds to each a value.
  3 件のコメント
Image Analyst
Image Analyst 2012 年 12 月 16 日
Should we assume T is less than 0, T is greater than 0, or must it be able to handle both?
Chris
Chris 2012 年 12 月 16 日
T>0, T= largest value of t

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

採用された回答

Image Analyst
Image Analyst 2012 年 12 月 16 日
Joe, is this what you mean?
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
t = linspace(0, 15, 350);
% Create some crazy function.
period = 5;
a = t .* abs(sin(2*pi*t/period) + 1);
% Plot it
subplot(3,1,1);
plot(t, a, 'b-', 'LineWidth', 3);
grid on;
title('Original Signal', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get the cdf
cdf = cumsum(a);
subplot(3,1,2);
plot(t, cdf, 'b-', 'LineWidth', 3);
grid on;
title('CDF of Original Signal', 'FontSize', fontSize);
% Let's say T = 5.
% Find out what element has t = 5
startingElement = find(t >= 5, 1, 'first')
% Get the integral from that point on.
subplot(3,1,3);
cdf5 = max(0, cdf - cdf(startingElement));
plot(t, cdf5, 'b-', 'LineWidth', 3);
grid on;
title('Integral of signal from 5 on', 'FontSize', fontSize);
  1 件のコメント
Chris
Chris 2012 年 12 月 16 日
編集済み: Chris 2012 年 12 月 16 日
No, but thankyou for your time. I'm sorry my question doesnt put forward what i wish. Though, finding the solution now, your answer has a part of it in it, and infact lead me to the solution.
For anyone looking for this answer, it was a combination of cumsum, and cumtrapz.

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

その他の回答 (2 件)

per isakson
per isakson 2012 年 12 月 16 日
See
quad
Numerically evaluate integral, adaptive Simpson quadrature
  1 件のコメント
John D'Errico
John D'Errico 2012 年 12 月 16 日
No! Quad is not the tool to do numerical integration of data vectors. Use trapz instead.

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


Image Analyst
Image Analyst 2012 年 12 月 16 日
Here's what my help for int says:
int
--- help for filtstates.int ---
int Convert a FILTSTATES.CIC object to an integer matrix.
int(Hs) returns an signed integer matrix for the FILTSTATES.CIC
object.
EXAMPLE:
Hm = mfilt.cicdecim;
hs = Hm.states; % Returns a FILTSTATES.CIC object
states = int(hs); % Convert object to a signed integer matrix.
See also
FILTSTATES/CIC.
Obviously not what you want. Depending on how you define integrate, you can use sum() or trapz().

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by