## How to convert from symbol to double?

### Christian (view profile)

on 19 Jan 2013
Accepted Answer by Walter Roberson

### Walter Roberson (view profile)

Hi,

I am pretty new to MATLAB, so this might be a stupid question. However, I am encountering a problem when i try to convert a matrix of 1x1 symbols into a matrix with doubles, where the symbols are converted to doubles each. Each element in the matrix is a function of a lot of symbols, which I need somehow to convert into numbers. I have something like this:

```    syms x y;
f = function of x and y
x = 2;
y = 3;
f.```

However, doing this gives me f as a function of the syms x and y, and not the numbers 2 and 3... Hope you can somehow help me, as Im kinda stuck in my coding.

Regards, Christian

## Products

No products are associated with this question.

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 19 Jan 2013

```double(subs(f))
```

Walter Roberson

### Walter Roberson (view profile)

on 19 Jan 2013

Because subs() would result in symbolic numbers after substitution. double() finishes the conversion to numeric.

Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 20 Jan 2013
```syms x
f=cos(x);
x=10;
y=subs(f);
whos y
```
Walter Roberson

### Walter Roberson (view profile)

on 20 Jan 2013

I do not have the Symbolic Toolbox to test this with.

### Azzi Abdelmalek (view profile)

Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 19 Jan 2013
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 19 Jan 2013

Use

```suyms x
f=cos(x);
x=10;
eval(f)
```

Walter Roberson

### Walter Roberson (view profile)

on 19 Jan 2013

No, do not eval() syms!

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi