Average value and RMS value
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
David Perez Ramos
am 2 Mär. 2015
Beantwortet: Star Strider
am 2 Mär. 2015
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?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 2 Mär. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!