繁体   English   中英

在MatLab中绘制符号函数

[英]Plotting symbolic function in MatLab

我在MatLab中绘制符号函数时遇到一些问题:例如,当我尝试使用ezplot绘制函数f时,其中:

f = 9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x

我收到以下错误:

Error using findstr
Inputs must be character arrays.

Error in ezplot>ezplot1 (line 442)
    if (isa(f, 'inline') && ~isempty(findstr(char(f), '=')))

Error in ezplot (line 145)
                [hp, cax] = ezplot1(cax, f{1}, vars, labels, args{:});

Error in sym/ezplot (line 61)
   h = ezplot(fhandle(f));

我试图将符号函数f转换为char形式,但返回类似错误:

Error using findstr
Inputs must be character arrays.

Error in ezplot>ezplot1 (line 442)
    if (isa(f, 'inline') && ~isempty(findstr(char(f), '=')))

Error in ezplot (line 145)
                [hp, cax] = ezplot1(cax, f{1}, vars, labels, args{:});

谢谢你的帮助!

您的函数定义必须有一些问题。 也许x定义不正确?

以下工作,至少在Matlab 2010b中有效。 它定义f为符号变量x符号函数

>> clear all
>> syms x
>> f = 9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x;
>> ezplot(f)

以下内容也有效。 它把f定义为一个字符串

>> clear all
>> f = '9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x';
>> ezplot(f)

如果将函数定义为匿名函数怎么办:

myfun = @(x)  4.5 - (((2*x)/5 - 2/5)*(x/3 - 17/6) - x);

figure
ezplot(myfun)

在此处输入图片说明

我真的不知道为什么ezplot命令不能与我的Matlab 2012b一起使用,所以我不得不采用像这样的残酷解决方案:(

syms x
f = 9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x;

k = 0.1;
x_p = 0:k:10;
y_p = subs(f,x,x_p);
plot(x_p,y_p)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM