How can I assign a character variable number in MATLAB?

I am trying to declare a symbolic variable in MATLAB using this code:

syms a; 

I do my calculations on this variable, and everything is fine. But my problem is that I do not know how I can assign a number to a variable and get the result as a number. For example, the answer of my code

  answer=exp(-10*a); 

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

  answer = 1.9152e-174 

I really appreciate any suggestion.

+4
source share
2 answers

use eval

 syms a; answer = exp(-10*a); a=40; eval(answer) ans = 1.9152e-174 
+7
source

You can use the SUBS function of the Symbolic Math Toolbox to perform symbolic replacements.

 syms a; answer = exp(-10*a); subs(answer,a,40) ans = 1.9152e-174 
+8
source

Source: https://habr.com/ru/post/1412252/


All Articles