Matlab排错:conversion to double from sym is impossile

一位Matlab新手尝试理解从负无穷到正无穷的Fourier变换与从零到正无穷的Fourier变换的区别,并试图使用Heaviside函数与余弦函数的乘积来实现后者的Fourier变换,但在尝试绘制变换结果时遇到了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

贴上答案,问题也是类似的:

"Nor Faizah " <a7khawarizmi@yahoo.com> wrote in message
news:flg079$77o$1@fred.mathworks.com...
> Hello everyone
>
> Actually i'm quite new to Matlab. I have a task on
> accessing some Matlab functions. At this moment, I try to
> look at the difference between the fourier transform which
> takes from -inf to inf and the fourier transform which
> takes from zero to inf.
>
> In order to do the latter part, I take the heaviside
> function and multiply with a cosine function (to start
> with). And find the fourier transform of the product.
>
> However, I don't have any idea how can I plot the result.
> Here is my try
>
> x=-10:0.1:10;
> %y = heaviside(x)
> % Heaviside(x) = 0, for x < 0
> % = 1, for x> 0
> y(x > 0) = 1;
> y(x == 0) = NaN;
> figure(1);plot(x,y); grid;
>
> g=cos(5*x);
> figure(2);plot(x,g);grid;
> G=y.*g;
> figure(3);plot(x,G);grid;
> F=fourier(G,w);

The FOURIER function is only defined for sym objects, so one or more of g,
y, or w must be a sym object. That means F will be a sym object as well,
and when you call PLOT two lines down from here ...

> ww=-10:0.1:10;
> figure(4);plot(ww,F);grid;
>
> And here is the Matlab response
> ??? Error using ==> plot
> Conversion to double from sym is not possible.

you receive this message, because PLOT doesn't know how to convert the sym
object into a double array for plotting. To correct this, you will need to
convert the sym object into a double array. The easiest way to do this, if
the expression F does not contain any instances of symbolic variables, is to
use double(F). If it does contain symbolic variables, use SUBS to
substitute values into that expression (and call DOUBLE on that result if
necessary.) Alternately, the EZPLOT function accepts sym objects and plots
them, so you could use that instead of PLOT.

Actually, thinking about this a little more, I don't think you want to use
FOURIER in this manner. Look in the M-file help for FOURIER -- it gives an
example that uses the Heaviside function directly, rather than passing a
vector of data to FOURIER.

--
Steve Lord
slord@mathworks.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值