error using matlabFunction : 'Error: argument must be of type 'Type:arithmetical' [cos]

8 ビュー (過去 30 日間)
I am attempting to write a symbolic matrix to a function using 'matlabFunction':
Here is my code, M_c is a 9x9 symbolic matrix: f = matlabFunction(M_c,'file','cluster_mass_eval')
This is the error I get:
??? Error using ==> mupadengine.mupadengine>mupadengine.feval at 162 Error: argument must be of type 'Type::Arithmetical' [cos]
Error in ==> sym.matlabFunction>optimize at 392 list = feval(symengine,'mlOptimizeWithIntermediates',f);
Error in ==> sym.matlabFunction>writeMATLAB at 367 [f,temps] = optimize(f);
Error in ==> sym.matlabFunction at 117 g = writeMATLAB(funs,file,varnames,outputs,body);
Is this saying that I can't have trigonometric functions of symbolic variables?
I am searching for the best way to be able to evaluate this symbolic matrix in a loop so if 'matlabFunction' isn't the best thing to use i welcome other suggestions.
Thanks, kyle
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 8 月 10 日
f = matlabFunction(M_c,'file','cluster_mass_eval','vars',{'theta', 'beta', 'p', 'q'})
Kyle Stanhouse
Kyle Stanhouse 2011 年 8 月 10 日
thanks
that fix worked....any observations on the other error?
if i use eval on my symbolic matrix i get this error:
beta=pi/4;theta=pi/3;p=10;q=10;eval(M_c)
??? Error using ==> evalin
Undefined function or method 'arg' for input arguments of
type 'double'.
Error in ==> sym.eval at 14
s = evalin('caller',vectorize(map2mat(char(x))));
Is it possible that my symbolic matrix is in a form that none of these evaluation functions will take?
I have gotten the matrix to evaluate previously by manually writing it to a file and tediously 'finding and replacing' notation that matlab won't evaluate (even though matlab symbolic manipulations output the expressions with said un-evaluate-able notation)....but i figured there has got to be a better way...
thanks,
kyle

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

採用された回答

Kai Gehrs
Kai Gehrs 2011 年 8 月 11 日
Hi,
just an additional comment: the names theta and beta are reserved names in MuPAD (which is the symbolic engine for the Symbolic Math Toolbox). They are the names of special functions - same as psi, gamma etc.
Depending on the version of MATLAB you are using, it may be necessary to avoid these names, since they cause name conflicts. This behavior is fixed in the more current MATLAB versions.
Best regards,
-- Kai

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 8 月 11 日
Do not use eval() on a symbolic value to try to substitute specific values for variables. Instead, use subs(), possibly followed by double()

Community Treasure Hunt

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

Start Hunting!

Translated by