How can I give a number to a symbolic variable in MATLAB?

£可爱£侵袭症+ 提交于 2019-12-19 03:25:18

问题


I try to declare a symbolic variable in MATLAB with this code:

 syms a;

I do my computation on this variable and all thing is fine. But my problem is that, I don't know how can I give a number to variable and get the result as a number. For example the answer of my code is

   answer=exp(-10*a);

For instance I want to give 40 to "a" and get the answer as

   answer = 
        1.9152e-174

I really appreciate any suggestion.


回答1:


use eval

syms a;
answer = exp(-10*a);

a=40;
eval(answer)

ans =
  1.9152e-174



回答2:


You can use the SUBS function from the Symbolic Math Toolbox to perform symbolic substitution.

syms a;
answer = exp(-10*a);

subs(answer,a,40)


ans =

  1.9152e-174


来源:https://stackoverflow.com/questions/10572269/how-can-i-give-a-number-to-a-symbolic-variable-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!