Prev: I cannot run Matlab 7.1 properly
Next: Saving particular workspace variable based on the "value"
From: Martin on 7 Apr 2010 08:26 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.
From: Steven Lord on 7 Apr 2010 09:31 "Martin " <martin3421(a)googlemail.com> wrote in message news:hphtlf$qj8$1(a)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? Strip off the "x = " portion of y first before trying to convert it to DOUBLE. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Martin on 7 Apr 2010 09:58 "Steven Lord" <slord(a)mathworks.com> wrote in message <hpi1e6$o85$1(a)fred.mathworks.com>... > > "Martin " <martin3421(a)googlemail.com> wrote in message > news:hphtlf$qj8$1(a)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? > > Strip off the "x = " portion of y first before trying to convert it to > DOUBLE. > > -- > Steve Lord > slord(a)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?
From: us on 7 Apr 2010 10:05 "Martin " <martin3421(a)googlemail.com> wrote in message <hphtlf$qj8$1(a)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
From: Martin on 7 Apr 2010 10:22 "us " <us(a)neurol.unizh.ch> wrote in message <hpi3f5$qcq$1(a)fred.mathworks.com>... > "Martin " <martin3421(a)googlemail.com> wrote in message <hphtlf$qj8$1(a)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!
|
Pages: 1 Prev: I cannot run Matlab 7.1 properly Next: Saving particular workspace variable based on the "value" |