[英]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.