Hello! I want to implement a formula such F(k)=k*symsum(x(n)*n,n,1,8). There is my code, but i don't know how to put vector x(n) in that sum. It doesn t work.
x=[1 3 5 4]
syms x k n
F(k)=k*symsum(x(n)*n,n,1,4)
That s my code. I want to do>>>>>>>>>>> F(k)=k*[x(1)*1+x(2)*2 +x(3)*3....], but i want the valueof x(1) and x(2)...
So the result may be>>>>>>>>>>>> F(k)=k*[1*1+3*2+5*3+4*4]

 採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 5 日

0 投票

You are attempting to index x with a symbolic variable. That is not possible with MATLAB, and that is something that is not expected to change any time soon.
Construct the definite terms instead
nx = x(:)*(1:length(x));
F(k) = k*nx;
Note that the first line is algebraic matrix multiplication * operator, column * row giving scalar result

3 件のコメント

Mihai Iustinian
Mihai Iustinian 2021 年 3 月 5 日
Ok, but if x=sin(2*pi*1/32*(0:127))? It is a sinusoidal signal with 4 period, represented on 128 point.
How do I construct x now?
Walter Roberson
Walter Roberson 2021 年 3 月 5 日
syms k
n = 1:128;
Pi = sym(pi);
x = sin(2*Pi*1/32*(n-1));
nx = simplify(n * x(:))
nx = 
F(k) = k*nx
F(k) = 
Mihai Iustinian
Mihai Iustinian 2021 年 3 月 6 日
Thanks!!!

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by