COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### conversion from symbolic to double

• Email
• Follow

```Hi
I've a problem when I want to convert a symbolic variable to double.
The example is from the MATLAB documentation.

>> syms x
>> f = sin(x^2);
>> y = feval(symengine, 'numeric::fsolve',f,'x=3')

y =

x = 3.069980123839465465438655

>> double(y)
??? Error using ==> sym.double at 29
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.

How can I convert the variable x to double?
VPA did not work, too. (or maybe I did it the wrong way)
Thanks for any hints.
```
 0

See related articles to this posting

```"Martin " <martin3421@googlemail.com> wrote in message
news:hphtlf\$qj8\$1@fred.mathworks.com...
> Hi
> I've a problem when I want to convert a symbolic variable to double.
> The example is from the MATLAB documentation.
>
>>> syms x
>>> f = sin(x^2);
>>> y = feval(symengine, 'numeric::fsolve',f,'x=3')
>
> y =
>
> x = 3.069980123839465465438655
>
>>> double(y)
> ??? Error using ==> sym.double at 29
> DOUBLE cannot convert the input expression into a double array.
> If the input expression contains a symbolic variable, use the VPA function
>
> How can I convert the variable x to double?

Strip off the "x = " portion of y first before trying to convert it to
DOUBLE.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

```
 0

```"Steven Lord" <slord@mathworks.com> wrote in message <hpi1e6\$o85\$1@fred.mathworks.com>...
>
> "Martin " <martin3421@googlemail.com> wrote in message
> news:hphtlf\$qj8\$1@fred.mathworks.com...
> > Hi
> > I've a problem when I want to convert a symbolic variable to double.
> > The example is from the MATLAB documentation.
> >
> >>> syms x
> >>> f = sin(x^2);
> >>> y = feval(symengine, 'numeric::fsolve',f,'x=3')
> >
> > y =
> >
> > x = 3.069980123839465465438655
> >
> >>> double(y)
> > ??? Error using ==> sym.double at 29
> > DOUBLE cannot convert the input expression into a double array.
> > If the input expression contains a symbolic variable, use the VPA function
> >
> > How can I convert the variable x to double?
>
> Strip off the "x = " portion of y first before trying to convert it to
> DOUBLE.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
thanks for the quick response!
But that means that I have to convert the variable into a string first?
>> z = char(y)

z =

x = 3.069980123839465465438655

>> u = z(5:end)

u =

3.069980123839465465438655

>> o = str2num(u)

o =

3.069980123839466

This way it works, thanks, but it looks a bit complicated to me.
Maybe there is an better way?
```
 0

```"Martin " <martin3421@googlemail.com> wrote in message <hphtlf\$qj8\$1@fred.mathworks.com>...
> Hi
> I've a problem when I want to convert a symbolic variable to double.
> The example is from the MATLAB documentation.
>
> >> syms x
> >> f = sin(x^2);
> >> y = feval(symengine, 'numeric::fsolve',f,'x=3')
>
> y =
>
> x = 3.069980123839465465438655
>
> >> double(y)
> ??? Error using ==> sym.double at 29
> DOUBLE cannot convert the input expression into a double array.
> If the input expression contains a symbolic variable, use the VPA function instead.
>
> How can I convert the variable x to double?
> VPA did not work, too. (or maybe I did it the wrong way)
> Thanks for any hints.

one of the few solutions

double(solve(y))
%    ans = 3.06998012383947     % <- format long g

us
```
 0

```"us " <us@neurol.unizh.ch> wrote in message <hpi3f5\$qcq\$1@fred.mathworks.com>...
> "Martin " <martin3421@googlemail.com> wrote in message <hphtlf\$qj8\$1@fred.mathworks.com>...
> > Hi
> > I've a problem when I want to convert a symbolic variable to double.
> > The example is from the MATLAB documentation.
> >
> > >> syms x
> > >> f = sin(x^2);
> > >> y = feval(symengine, 'numeric::fsolve',f,'x=3')
> >
> > y =
> >
> > x = 3.069980123839465465438655
> >
> > >> double(y)
> > ??? Error using ==> sym.double at 29
> > DOUBLE cannot convert the input expression into a double array.
> > If the input expression contains a symbolic variable, use the VPA function instead.
> >
> > How can I convert the variable x to double?
> > VPA did not work, too. (or maybe I did it the wrong way)
> > Thanks for any hints.
>
> one of the few solutions
>
>      double(solve(y))
> %    ans = 3.06998012383947     % <- format long g
>
> us
Thank you!
```
 0

4 Replies
1624 Views

Similar Articles

11/30/2013 4:21:44 AM
page loaded in 55873 ms. (0)