Hi, I trying to make a simple program, I would like to know how to make this
syms x; fun=x^2; x0=2;
x=x0; fun
And what a expect in the last line is 4 but I get X^2 How can I convert the sym to a double, I tried with doble(fun).
thank you

 Réponse acceptée

Walter Roberson
Walter Roberson le 31 Jan 2011

8 votes

syms x;
fun=x^2;
x0=2;
subs(fun,x,x0)
double(ans)

Plus de réponses (3)

Behrooz Shahsavari
Behrooz Shahsavari le 29 Déc 2013

11 votes

If you want to evaluate that symbolic function in a large number of points (e.g. x = 1:10000), an effective way is to convert it to a MATLAB function handle as follows:
x0 = 1:10000; % Assume that we want to evaluate the function in these points
FUN = matlabFunction(fun); % This creates a function handle
y = feval(FUN, x0); % Evaluates the new function handle at the specified points

1 commentaire

Zhe Chen
Zhe Chen le 24 Fév 2020
matlabFunction is a very useful function.

Connectez-vous pour commenter.

Paulo Silva
Paulo Silva le 31 Jan 2011

1 vote

try this way
fun=inline('x^2')
x0=2
fun(x0)
Julio Cesar
Julio Cesar le 31 Jan 2011

1 vote

thank you!!! both work great :D

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by