I've some problems in plotting a symbolic function in MatLab: for example when I try to plot the function f with ezplot, where:
f = 9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x
I get the following error:
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));
I've tried to convert the symbolic function f in the char form but it returns an analogous error:
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{:});
Thanks for any help!
You must have some problem with you function definition. Perhaps x
has been defined incorrectly?
The following works, at least in Matlab 2010b. It defines f
as a symbolic function of the symbolic variable x
:
>> clear all
>> syms x
>> f = 9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x;
>> ezplot(f)
The following is also valid. It defines f
as a string :
>> clear all
>> f = '9/2 - ((2*x)/5 - 2/5)*(x/3 - 17/6) - x';
>> ezplot(f)
What if you define your function as an anonymous function:
myfun = @(x) 4.5 - (((2*x)/5 - 2/5)*(x/3 - 17/6) - x);
figure
ezplot(myfun)
I really don't know why the ezplot
command doesn't work with my Matlab 2012b, so I had to go with a brutal solution like this :(
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.