2017-01-19 14 views
1

質問

オクターブ内のメッセージ「文字列またはインライン関数でなければならないFUN」の意味は何である「FUNは、文字列またはインライン関数でなければなりませんか」?オクターブ

Octave 4.2.0(Windows)Gradients, Gradient Plots and Tangent Planesは本来MATLAB 7.8で実装されており、以下のようなエラーが出ました。

これは、OctaveがMATLABと互換性がないか、または他の原因があるためです。回避策がある場合は、お手数ですがお勧めします。

>> syms x y z 
>> f=((x^2-1)+(y^2-4)+(x^2-1)*(y^2-4))/(x^2+y^2+1)^2 
f = (sym) 

    2 2 /2 \/2 \ 
    x + y + \x - 1/*\y - 4/ - 5 
    ------------------------------- 
         2 
     /2 2 \ 
      \x + y + 1/ 

>> gradf=jacobian(f,[x,y]) 
gradf = (sym 1x2 matrix) 

    [ /2 2 /2 \/2 \ \  /2 \   /2 2 
    [ 4*x*\x + y + \x - 1/*\y - 4/ - 5/ 2*x*\y - 4/ + 2*x 4*y*\x + y 
    [- ------------------------------------- + ------------------ - ------------- 
    [       3        2 
    [   /2 2 \    /2 2 \     /
    [    \x + y + 1/     \x + y + 1/     \ 

    /2 \/2 \ \  /2 \  ] 
    + \x - 1/*\y - 4/ - 5/ 2*y*\x - 1/ + 2*y] 
    ------------------------ + ------------------] 
       3        2 ] 
    2 2 \    /2 2 \ ] 
    x + y + 1/     \x + y + 1/ ] 

>> [xx, yy] = meshgrid(-3:.1:3,-3:.1:3); 
>> ffun = @(x,y) eval(vectorize(f)); 
>> fxfun = @(x,y) eval(vectorize(gradf(1))); 
>> fyfun = @(x,y) eval(vectorize(gradf(2))); 
>> contour(xx, yy, ffun(xx,yy), 30) 
error: vectorize: FUN must be a string or inline function 
error: called from 
    @<anonymous> at line 1 column 15 

答えて

3

vectorizeは、文字列リテラルを期待し、シンボリック式から関数ハンドルを取得するために失敗したようですが、あなたの代わりにfunction_handleを使用することができます。

次ベクトルフレンドリーになり
ffun = function_handle(f) 

機能:

あなた contourコールで、たとえば、以降使用することができ
ffun = 
@(x, y) (x .^ 2 + y .^ 2 + (x .^ 2 - 1) .* (y .^ 2 - 4) - 5) ./ (x .^ 2 + y .^ 2 + 1) .^ 2 

contour(xx, yy, ffun(xx,yy), 30) 

enter image description here

関連する問題