필터 지우기
필터 지우기

Cannot extract real or imag part of a function

조회 수: 4 (최근 30일)
Fine
Fine 2023년 9월 30일
댓글: Paul 2023년 10월 1일
I Fourier-transformed a bymbolic expression and turned it into a function, but cannot use real or imag functions for it. The error is: Incorrect number or types of inputs or outputs for function real.
syms x
f = 1/(1+28*1i)+28*1i/(x-1i);
f_FT = fourier(f);
f_ft = matlabFunction(f_FT);
R = real(f_ft);
I = imag(f_ft);

채택된 답변

Star Strider
Star Strider 2023년 9월 30일
You are taking the real and imag parts of a function handle. It is necessary to evaluate the function handle first.
Try this —
syms x omega
f = 1/(1+8*1i)+8*1i/(x-1i);
f_FT = fourier(f, omega)
f_FT = 
f_ft = matlabFunction(f_FT)
f_ft = function_handle with value:
@(omega)pi.*dirac(omega).*(3.076923076923077e-2-2.461538461538462e-1i)+pi.*exp(omega).*(sign(omega)-1.0).*8.0
omegav = linspace(0, pi, 25);
ft = f_ft(omegav);
R = real(f_ft(omegav))
R = 1×25
Inf 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I = imag(f_ft(omegav))
I = 1×25
-Inf 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The presence of the term makes a plot essentially impossible.
.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 9월 30일
f_ft is a function handle. The only operations supported for function handles are copying, assignment, invocation, display, functions() which returns information.
You could take the real() of the symbolic expression and matlabFunction that, or you could invoke the handle on specific values and real() the result.
  댓글 수: 1
Paul
Paul 2023년 10월 1일
Before taking real() and imag() of the symbolic expression, the transform variable should be declared as real
syms x
f = 1/(1+28*1i)+28*1i/(x-1i);
f_FT = fourier(f)
f_FT = 
[real(f_FT) imag(f_FT)].'
ans = 
syms w real
[real(f_FT) imag(f_FT)].'
ans = 
But taking the matlabFunction at this point might not be useful because of the diracs.

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

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by