Info

This question is closed. Reopen it to edit or answer.

How do I solve this problem?

1 view (last 30 days)
Mohamed El-Behairy
Mohamed El-Behairy on 15 May 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
This is what's on my mind:
n=-10:10;
x= .....;
E=sum(abs(x).^2);
Pav=E/length(x);
I don't know how to represent x which should be the function itself and I don't know how to transform it to a loop.
  3 Comments
Mohamed El-Behairy
Mohamed El-Behairy on 16 May 2015
@Walter yes it does
Joseph Cheng
Joseph Cheng on 16 May 2015
start off small and define u[n] first as a function or condition. let me suggest looking up anonymous functions.

Answers (1)

Walter Roberson
Walter Roberson on 16 May 2015
function r = u(s)
if s <= 0
r = 0;
else
r = 1;
end
end
Now you can call u(n) and u(n-k) in your loop in calculate x(n)
  3 Comments
Joseph Cheng
Joseph Cheng on 16 May 2015
Edited: Joseph Cheng on 16 May 2015
as you confirmed u[n] is the Heaviside function which is 1 when n>0 and 0 for n<=0. Walter created a function which checks the input 's' to see if it is less than 0 which then outputs 0, otherwise the output is 1. (or when s>0)
But i thought the heaviside was 1 at 0 such that n>=0 was 1.
Walter Roberson
Walter Roberson on 16 May 2015
There is no definition of the value of Heaviside(0) . 0, 1, and 1/2 are all common. See HeavisideAtOrigin in Symbolic Toolbox Heaviside.
It's a simple enough edit to change the definition.
K = 4;
for J = [2 3 4 5 6 7]
uJ = u(J);
uJK = u(J-K);
disp(uJ - uJK);
end

Community Treasure Hunt

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

Start Hunting!