How does symvar work?

Hi all!
symvar 'cos(2*pi*t)'
How can I make symvar to not return 't'?
I use this: syms t
but no success.

 Réponse acceptée

Paulo Silva
Paulo Silva le 7 Juin 2011

1 vote

symvar gives you the symbolic variables inside one expression, you say that t is symbolic so the expression symvar('cos(2*pi*t)') gives you t, I can't imagine why you don't wan't to get the t.

3 commentaires

sadel
sadel le 7 Juin 2011
Well here is my main problem: http://www.mathworks.com/matlabcentral/answers/8905-how-can-i-create-a-function-which-evaluate-only-strings-which-represent-only-mathematical-functions
I saw that symvar returns identifiers other than i, j, pi, inf, nan, eps, and common functions and I believe that if I make it to identify the 't' from a string like this 'cos(2*pi*t)' , then I can reach my target
sadel
sadel le 7 Juin 2011
If I could make symvar to identify the symbol 't' and doesn't return it then I could create
a function which evaluate only strings which represent only mathematical functions
t=0:0.1:10;
insertfunction='cos(2*pi*t))'
gh=symvar(insertfunction)
if (gh is an empty cell array)
eval(['v =0*t+ ',vectorize(gh),';'])
plot(t,v)
end
Paulo Silva
Paulo Silva le 9 Juin 2011
t=0:0.1:10;
insertfunction='cos(2*pi*t))'
gh=symvar(insertfunction)
if (numel(gh)==1) %see if there's only one symbolic variable (just the t)
eval(['v =0*t+ ',vectorize(gh),';'])
plot(t,v)
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by