MATLAB Answers

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.

164 views (last 30 days)
Mehmet Güneri
Mehmet Güneri on 20 Dec 2020
Commented: Rik on 21 Dec 2020
This question was flagged by John D'Errico
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 Comments

Show 8 older comments
Rik
Rik on 21 Dec 2020
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 20 Dec 2020
fplot(abs(hf), [-20*pi 20*pi])

  5 Comments

Show 2 older comments
Walter Roberson
Walter Roberson on 20 Dec 2020
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 on 21 Dec 2020
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by