Hello Community,
i try to calculate the root mean square of a piecwise function.
I had different approaches, but all them don't work.
1. Approach
syms t
y = piecewise(0<=t<=2,-sin(2*pi/8*t));
rms = rms(y);
Error Message: Error using sym/subsindex (line 953)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
2. Approach
syms t
y = piecewise(0<=t<=2,-sin(2*pi/8*t));
t = 0:0.001:2;
z = subs(y);
m = double(z);
rms = rms(m);
Error Message: Array indices must be positive integers or logical values.
I don't know any other approach.
I hope, I expressed my problem appropriatly.
Thanks for your help!
Smitty

 채택된 답변

Sam Chak
Sam Chak 2022년 7월 15일

1 개 추천

Can you check if this is the expected RMS value over the interval ?
t = linspace(0, 2, 2001);
y = - sin(2*pi/8*t);
v = rms(y)
v = 0.7071
plot(t, y)

댓글 수: 2

Smitty
Smitty 2022년 7월 15일
Yes, that is the expected RMS. My problem is to get it for Functions, that I define with "Piecewise" so that I can combine Rectangle und Sinus Signals.
Smitty
Smitty 2022년 7월 15일
편집: Smitty 2022년 7월 15일
It just came to my mind, that i can just implement the RMS by myself.
syms t
y = piecewise(0<=t<=2,sin(2*pi/8*t));
T = 2;
RMS = sqrt(1/T*int(y^2,0,T));
That works fine.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 7월 15일

편집:

2022년 7월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by