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 CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by