我在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));
我试图在char表单中转换符号函数f,但它返回一个类似的错误:
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{:});
感谢您的帮助!
答案 0 :(得分:1)
您的功能定义必定有问题。可能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)
答案 1 :(得分:0)
如果将函数定义为匿名函数,该怎么办:
myfun = @(x) 4.5 - (((2*x)/5 - 2/5)*(x/3 - 17/6) - x);
figure
ezplot(myfun)
答案 2 :(得分:0)
我真的不知道为什么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)