PLEASE how to implement sigma in matlab

there are two input signals x1[nT] and x2[nT] given, and sample spacing is given as T=0.1. i'm struggling to code x2[nT].
t = -0.7:0.7;
T = 0.1;
n = -0.7/T:0.7/T; % discrete-time values (from t=nT)
x1=tan(pi*n/3)+2*exp(-0.8*abs(n));
k=-7:1:n;
s=0.2.^abs(k);
S=sum(s);
x2=0.6.^abs(n)+S;
when i implement stem(n*T, x2), the graph shows wrong as the value k stops at -7 and doesn't move on. how can i fix this code? Thanks

2 件のコメント

Walter Roberson
Walter Roberson 2018 年 4 月 29 日
Please do not close questions that have an answer.
Rena Berman
Rena Berman 2018 年 5 月 15 日
(Answers Dev) Restored edit

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 29 日

1 投票

Your n is a vector. When you use k=-7:1:n then you have a vector on the right hand side. MATLAB says that if you have a vector on the left or right side of a ":" then the result is the same as if you used only the first element. So your statement is effectively k=-7:1:n(1) which is k=-7:1:(-0.7/.1) which is k=-7:1:-7 which is just -7 .
Note: 0.1 cannot be exactly represented in binary floating point, -0.7/.1 could come out slightly more negative than -7, leading to k=-7:1:(-7-something) which would be empty. You should avoid division in specifying a colon range. You would be better off with
n = -7 : 1 : 7;
T = 0.1;
t = n * T;
As for your difficulty with k=-7:n : you are assuming that you have a vector of n, whereas the formula is for scalar n. But if you want to vectorize then,
n = -7:7;
syms N
subs(symsum(sym(0.2)^abs(k),k,-7,N), N, n)

2 件のコメント

Walter Roberson
Walter Roberson 2018 年 4 月 29 日
Remember to
syms k
Walter Roberson
Walter Roberson 2018 年 4 月 29 日
0.2^2 is less than 0.2^1, so sum(0.2.^[7 6 5 4 3 2 1 0]) must be strictly less than 8 * 0.2, which is 1.6 . So 1+(0.2^7 + 0.2^6 + ...+0.2^0) must be strictly less than 2.6, and nowhere near 11.
For 1+sum(x.^[7 6 5 4 3 2 1 0]) to be equal to 11, your x must be slightly greater than 1 -- about 1.06286984041761

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by