The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.

조회 수: 77 (최근 30일)
Hi! I am trying to plot a fourier function by using fplot but I am getting the following error.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing symbolic variables into double array.
Apply 'subs' function first to substitute values for variables.
syms f(t) g(t) w;
x=@(t)heaviside(exp(-20*t));
h=@(t) heaviside(12.*t.*exp(55*t));
xf=vpa(fourier(f,t,w));
hf=vpa(fourier(g,t,w));
fplot(@(w) abs(hf), [-20*pi 20*pi])
  댓글 수: 11
Rik
Rik 2020년 12월 21일
Which function exactly do you want to plot? As Walter mentioned below, you can't plot the idea of a Fourier transform. I expect you want to plot the Fourier transform of either x or h. You don't actually use either in your current code.

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 20일
fplot(abs(hf), [-20*pi 20*pi])
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 12월 20일
Nothing. You cannot illustrate the general idea of fourier transformation without using a series of plots. I recommend that you look at Wikipedia or some textbooks to see how they illustrate the general idea of fourier transform of unknown functions.
In the meantime, I would like to ask you why you go through the trouble to calculate xf but do not display the results and do not plot it? Why do you suddenly turn around and want to plot the fourier transform of the unknown function g?
Walter Roberson
Walter Roberson 2020년 12월 21일
Oh, right, you did not define f either.
You can potentially plot the fourier transform of x or h, but not of the undefined functions f or g.
sympref('HeavisideAtOrigin', 1)
ans = 
syms t w real
x=@(t)heaviside(exp(-20*t));
h=@(t) heaviside(12.*t.*exp(55*t));
f = fourier(x, t, w)
f = 
af = abs(f)
af = 
W = (-20:20)*pi;
AF = subs(af, w, W)
AF = 
try
plot(W, AF)
catch
fprintf('Ooops, abs(f) cannot be plotted!');
end
g = fourier(h, t, w)
g = 
ag = abs(g)
ag = 
AG = subs(ag, w, W)
AG = 
try
plot(W, AG)
catch
fprintf('Ooops, abs(g) cannot be plotted!');
end
Ooops, abs(g) cannot be plotted!
What went wrong? Well, it turns out that the Fourier transform of the Heaviside function is tricky to derive ( https://www.cs.uaf.edu/~bueler/M611heaviside.pdf ) and MATLAB simply doesn't have it registered in its table of functions. The transform does exist; see https://www.wolframalpha.com/input/?i=Fourier%5BHeaviside%5B12*t*Exp%5B55*t%5D%5D%2Ct%2Cw%5D -- though I notice that if I adjust the constant multipliers that Wolfram Alpha always gives the same result, and I am not positive that is correct.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by