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

 채택된 답변

Walter Roberson
Walter Roberson 2011년 1월 31일

8 개 추천

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

추가 답변 (3개)

Behrooz Shahsavari
Behrooz Shahsavari 2013년 12월 29일

11 개 추천

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

Zhe Chen
Zhe Chen 2020년 2월 24일
matlabFunction is a very useful function.

댓글을 달려면 로그인하십시오.

Paulo Silva
Paulo Silva 2011년 1월 31일

1 개 추천

try this way
fun=inline('x^2')
x0=2
fun(x0)
Julio Cesar
Julio Cesar 2011년 1월 31일

1 개 추천

thank you!!! both work great :D

카테고리

질문:

2011년 1월 31일

댓글:

2020년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by