how can i solve the error "Undefined function 'sign' for input arguments of type 'sym'."

14 ビュー (過去 30 日間)
Paolo
Paolo 2013 年 9 月 29 日
編集済み: Wayne King 2013 年 9 月 29 日
i have the following function
function [S] = Signfunciton(f,a,b)
v=-a:0.5:b;
S= f(v);
S=sign(S);
then i give it inputs
>>syms x
>>f(x)=3*x+2
>>Signfunction(f,4,5)
but i always get the error "Undefined function 'sign' for input arguments of type 'sym'."
how can i solve this?? thank you

採用された回答

Wayne King
Wayne King 2013 年 9 月 29 日
Do you have the Symbolic Toolbox?
And if you do, why aren't you just doing
syms x;
f = 3*x+2;
sign(subs(f,-4:0.5:5))
  1 件のコメント
Paolo
Paolo 2013 年 9 月 29 日
i don't know what a symbolic toolbox is but i used your code and it works great. but i still don't understand what was wrong with my code.

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2013 年 9 月 29 日
編集済み: Wayne King 2013 年 9 月 29 日
Yours works for me:
function [S] = Signfunction(f,a,b) %you misspelled this above
v=-a:0.5:b;
S= f(v);
S=sign(S);
Then execute:
syms x;
f(x) = 3*x+2;
Signfunction(f,4,5);
Note if you don't want a symbolic output
clearvars x;
f = @(x) 3*x+2;
S = Signfunction(f,4,5);
Now S is a double-precision vector.

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by