Average value and RMS value

3 ビュー (過去 30 日間)
David Perez Ramos
David Perez Ramos 2015 年 3 月 2 日
回答済み: Star Strider 2015 年 3 月 2 日
Hello, I am trying to verify functions taking the average and RMS value using trapz function,but I am not getting the right answer in matlab. according to the theory in the book the average value of a function is obtained by: 1/(b-a)∫〖5sin(t)〗, across the interval a<t<b. This is what I have done:
EDITOR:
%Verify that the average value for F(t)=5sin(t), is zero.
%Verify that the RMS value for F(t)=5sin(t), is 3.535.
function z= myfun2(t)
a = 1;
b = 3;
z =(1/b-a)*(5*sin(t)); %function for average value.
end
COMMAND WINDOW:
>> t = linspace(1,3,400);
>> z = myfun2(t);
>> average = trapz(t,z)
average =
-5.1010
When I do it by hand, I do get zero for the average value, but in matlab and dont get zero. Is something wrong in my z function?

採用された回答

Star Strider
Star Strider 2015 年 3 月 2 日
I’m guessing at what your problem actually says, but the problem may be the ‘a’ and ‘b’ limits. Adding pi to them as a factor, and correcting the definition of mean value:
myfun2 = @(t) 5*sin(t);
a = pi;
b = 3*pi;
t = linspace(a,b,400);
z = myfun2(t);
average = trapz(t,z)./(b-a)
produces:
average =
-95.6651e-018
which is essentially zero to floating-point precision.
The mean value is Integral(f(t),a,b)/(b-a).

その他の回答 (0 件)

カテゴリ

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