フィルターのクリア

plot integral

4 ビュー (過去 30 日間)
mouna
mouna 2011 年 5 月 19 日
コメント済み: Vignesh Sella 2020 年 2 月 28 日
good morning
I have this equationy(t)=integral of((C(t)*dt)) (0-->t) i haven't the equation of C(t) but i have the values of C(t) in each minute i need to plot y(t) how i can do it???
thanks in advance
  2 件のコメント
Yoav Livneh
Yoav Livneh 2011 年 5 月 19 日
How is y a function of t if you integrate C(t) over t?
Vignesh Sella
Vignesh Sella 2020 年 2 月 28 日
good morning!

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

回答 (2 件)

Sarah Wait Zaranek
Sarah Wait Zaranek 2011 年 5 月 26 日
This can be done using cumtrapz --
Doc here:
Code example below using points taken from a sine wave:
X = linspace(0,2*pi,100);
Y = sin(X);
Z = cumtrapz(X,Y);
plot(X , [Y; Z])

Charles Cunningham
Charles Cunningham 2013 年 7 月 1 日
Sarah, thank you for pointing out the use of cumtrapz. That answer also helped me make progress with a scrpit I'm wokring on. I did notice a discrepancy with the result for Z and it took a little bit to figure out why. So I thought I'd share what I found.
The integral of sin(x)dx is -cos(x).
After executing your code I expected to see the plot of Z to match a plot of -cos(x). However, it did not. To illustrate this point plot the following (based on Sarah's code):
plot(X , [Z; -cos(X)])
Notice that the result Z is -cos(x) offset by a constant.
I was then reminded of 2 things:
  1. The integral of f(x)dx is f(x)/dx + constant.
  2. That cumtrapz is an esimation to find an integral.
The estimation includes the constant. So you can correct the estimation of this integral by subtracting that constant. Then the proper result will be plotted. Update Z to the following equation:
Z = cumtrapz(X,Y) - 1;

カテゴリ

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