フィルターのクリア

Differentiation error - conversion of variable type problem - 'struct' to function

2 ビュー (過去 30 日間)
Tam Ho
Tam Ho 2017 年 12 月 29 日
回答済み: Walter Roberson 2017 年 12 月 29 日
I ran this code:
syms theta %create symbolic variable theta
assume(theta,'real') %theta is real
f = fit_v2; %calling our fitted polynomials
g = diff(f,theta);
g0=solve(g,theta);
double(g0);
I get this error:
Error using sym>tomupad (line 1251)
Unable to convert 'struct' to 'sym'.
Error in sym (line 215)
S.s = tomupad(x);
Error in sym/privResolveArgs (line 988)
argout{k} = sym(arg);
Error in sym/diff (line 21)
args = privResolveArgs(S,varargin{:});
Error in code (line 54)
g = diff(f,theta);
please help! Thanks!
  1 件のコメント
Tam Ho
Tam Ho 2017 年 12 月 29 日
I think I know why.
fit_v2 is a 'struct' variable type:
f =
struct with fields:
type: 'polynomial degree 10'
coeff: [0.0012 4.2344e-04 -0.0101 -0.0033 0.0303 0.0097 -0.0373 -0.0126 0.#### 0.#### #.####]
how can I conveniently convert fit_v2 to get f in function form and ready to be differentiated?

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 12 月 29 日
poly = poly2sym(f.coeff, theta);
g = diff(poly, theta)
However, you do not need the symbolic toolbox to differentiate a polynomial with numeric terms, and you do not need the symbolic toolbox to get the roots of a polynomial with numeric terms (you can use roots())

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by