Problem with ploting involving function handle

조회 수: 65 (최근 30일)
Tsz Tsun
Tsz Tsun 2024년 10월 13일
편집: Matt J 2024년 10월 15일
Hi all, I encounter the following error when I want to plot a function involving function handle with symsum, I cannot figure out the error. My code is as follows. In my matlab 2023b, I receive the following error:
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in FunctionLine update: Undefined function 'symsum' for input arguments of type 'double'.
N= 600
N = 600
sym ii
COMx_k = @(k) symsum(1.*exp(-2*pi*1i*(k/N)*ii), ii,1,N)
COMx_k = function_handle with value:
@(k)symsum(1.*exp(-2*pi*1i*(k/N)*ii),ii,1,N)
%k=0:0.1:300
fplot(COMx_k)
xlabel('k')
ylabel('COMx_k')
Warning: Error in state of SceneNode.
The following error was reported evaluating the function in FunctionLine update: Unrecognized function or variable 'ii'.

채택된 답변

Matt J
Matt J 2024년 10월 13일
편집: Matt J 2024년 10월 15일
Perhaps this is what you meant?
N= 600;
COMx_k = @(k) real(sum(1.*exp(-2*pi*1i*(k/N).*(1:N)' ),1));
%k=0:0.1:300
fplot(COMx_k,[0,300])
xlabel('k')
ylabel('COMx_k')
  댓글 수: 6
Tsz Tsun
Tsz Tsun 2024년 10월 15일
Yes, in fact I am trying to do a DFT. I just notice that there is a function package called fft(X) in matlab, but I am not sure if fft(X) is doing the job of DFT.
Walter Roberson
Walter Roberson 2024년 10월 15일
fft() does a two-sided numeric discrete fourier transform.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 10월 13일
sym ii
That is equivalent to
ans = sym('ii');
which creates the symbolic symbol ii but throws away the reference to the symbolic symbol.
What you probably wanted was
N= 600
syms ii
COMx_k = @(k) symsum(1.*exp(-2*pi*1i*(k/N)*ii), ii,1,N)
fplot(COMx_k)
xlabel('k')
ylabel('COMx_k')
However, this takes a fair amount of time to plot !!
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 10월 13일
@(k) symsum(1.*exp(-2*pi*1i*(k/N)*ii), ii,1,N)
That is complex-valued when k is not an integer, and is 0 when k is an integer.

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

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by