Cannot extract real or imag part of a function
4 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
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 = matlabFunction(f_FT)
omegav = linspace(0, pi, 25);
ft = f_ft(omegav);
R = real(f_ft(omegav))
I = imag(f_ft(omegav))
The presence of the term makes a plot essentially impossible.
.
0 个评论
更多回答(1 个)
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
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)
[real(f_FT) imag(f_FT)].'
syms w real
[real(f_FT) imag(f_FT)].'
But taking the matlabFunction at this point might not be useful because of the diracs.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!