164 views (last 30 days)

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])

Walter Roberson
on 20 Dec 2020

fplot(abs(hf), [-20*pi 20*pi])

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
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)

syms t w real

x=@(t)heaviside(exp(-20*t));

h=@(t) heaviside(12.*t.*exp(55*t));

f = fourier(x, t, w)

af = abs(f)

W = (-20:20)*pi;

AF = subs(af, w, W)

try

plot(W, AF)

catch

fprintf('Ooops, abs(f) cannot be plotted!');

end

g = fourier(h, t, w)

ag = abs(g)

AG = subs(ag, w, W)

try

plot(W, AG)

catch

fprintf('Ooops, abs(g) cannot be plotted!');

end

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.

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

Start Hunting!
## 11 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1218605

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1218605

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219305

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219305

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219475

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219475

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219485

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219485

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219500

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219500

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219535

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219535

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219565

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219565

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219570

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219570

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219575

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219575

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219580

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1219580

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1220075

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/698380-the-following-error-was-reported-evaluating-the-function-in-functionline-update-unable-to-convert-e#comment_1220075

Sign in to comment.