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

2

5

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.

Raney answered 13/5, 2012 at 13:47 Comment(0)
D
9

use eval

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

a=40;
eval(answer)

ans =
  1.9152e-174
Deterge answered 13/5, 2012 at 14:3 Comment(0)
B
10

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
Brethren answered 13/5, 2012 at 16:58 Comment(0)
D
9

use eval

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

a=40;
eval(answer)

ans =
  1.9152e-174
Deterge answered 13/5, 2012 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.