MatLab中符号函数的绘制
我在MatLab中绘制符号函数时遇到一些问题:例如,当我尝试使用ezplot绘制函数f时,其中:MatLab中符号函数的绘制,matlab,plot,Matlab,Plot,我在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(cha
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{:});
谢谢你的帮助 如果将函数定义为匿名函数,该怎么办:
myfun = @(x) 4.5 - (((2*x)/5 - 2/5)*(x/3 - 17/6) - x);
figure
ezplot(myfun)
您的函数定义一定有问题。也许
x
的定义不正确
下面的工作,至少在Matlab2010b中。它将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)
我真的不知道为什么
ezplot
命令不能与我的Matlab 2012b一起工作,所以我不得不采用这样一个残酷的解决方案:(
我不能使用这个表达式,因为我有一个给定的符号表达式向量,就像我之前发布的一样。哦,我明白了,很抱歉。我在我的程序中将f和变量x都定义为符号!我认为这是一个黑魔法,但我重复了很多次,在代码前后清除工作空间,但仍然不起作用!
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)