### Tags: code, conversion, double, elements, matlab, matrix, programming, run, sym, templ, uc1231

# Conversion to double from sym is not possible

On Programmer » Matlab

4,487 words with 2 Comments; publish: Wed, 07 May 2008 20:28:00 GMT; (200171.88, « »)

Hi....I tried to run this code to get two elements of a matrix :

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%

tempL = UC{1,4}; %we will be working on one cell at the time

syms x y

Eq1 = tempL(:,1)'*[tempL(1:6,3);x;y]

Eq2 = tempL(:,2)'*[tempL(1:6,3);x;y]

[x,y] = solve(Eq1,Eq2)

tempL(7,3) = x

tempL(8,3) = y

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%

I got this error message :

? Conversion to double from sym is not possible.

Error in ==> test at 28

tempL(7,3) = x

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%

then I tried to cast the x and y to double:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%

tempL = UC{1,4}; %we will be working on one cell at the time

syms x y

Eq1 = tempL(:,1)'*[tempL(1:6,3);x;y]

Eq2 = tempL(:,2)'*[tempL(1:6,3);x;y]

[x,y] = solve(Eq1,Eq2)

tempL(7,3) = double(x)

tempL(8,3) = double(y)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%

I got this error message :

? Error using ==> str2num

Requires string or character array input.

Error in ==> sym.double at 17

X = str2num(map2mat(char(maple('evalf',S(:),

d))));

Error in ==> test at 28

tempL(7,3) = double(x)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%

Can anyone help me to solve this ?

*http://matlab.todaysummary.com/q_matlab_10170.html*

All Comments

Leave a comment...

- 2 Comments
- "A. Abdullah" <abadee15.matlab.todaysummary.com.hotmail.com> wrote in message
news:ef3b87d.-1.matlab.todaysummary.com.webcrossing.raydaftYaTP...

> Hi....I tried to run this code to get two elements of a matrix :

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%

> tempL = UC{1,4}; %we will be working on one cell at the time

> syms x y

> Eq1 = tempL(:,1)'*[tempL(1:6,3);x;y]

> Eq2 = tempL(:,2)'*[tempL(1:6,3);x;y]

> [x,y] = solve(Eq1,Eq2)

> tempL(7,3) = x

> tempL(8,3) = y

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%

> I got this error message :

> ? Conversion to double from sym is not possible.

> Error in ==> test at 28

> tempL(7,3) = x

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%

> then I tried to cast the x and y to double:

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%

> tempL = UC{1,4}; %we will be working on one cell at the time

> syms x y

> Eq1 = tempL(:,1)'*[tempL(1:6,3);x;y]

> Eq2 = tempL(:,2)'*[tempL(1:6,3);x;y]

> [x,y] = solve(Eq1,Eq2)

> tempL(7,3) = double(x)

> tempL(8,3) = double(y)

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%

> I got this error message :

> ? Error using ==> str2num

> Requires string or character array input.

> Error in ==> sym.double at 17

> X = str2num(map2mat(char(maple('evalf',S(:),

d))));

> Error in ==> test at 28

> tempL(7,3) = double(x)

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%

> Can anyone help me to solve this ?

Either x or y contains a symbolic variable -- you can't convert something

like '6*x' into a double. Either convert tempL into an array of sym objects

or substitute values into x and y before calling DOUBLE on them to remove

all symbolic variables from them.

Steve Lord

slord.matlab.todaysummary.com.mathworks.com

#1; Wed, 07 May 2008 20:29:00 GMT

- "A. Abdullah" <abadee15.matlab.todaysummary.com.hotmail.com> wrote in message
- Steven Lord wrote:
>

> "A. Abdullah" <abadee15.matlab.todaysummary.com.hotmail.com> wrote in message

> news:ef3b87d.-1.matlab.todaysummary.com.webcrossing.raydaftYaTP...

:

> Either x or y contains a symbolic variable -- you can't convert

> something

> like '6*x' into a double. Either convert tempL into an array of

> sym objects

> or substitute values into x and y before calling DOUBLE on them to

> remove

> all symbolic variables from them.

> --

> Steve Lord

> slord.matlab.todaysummary.com.mathworks.com

>

> When I run the code :

x =

[ empty sym ]

y =

[]

because in my case there is no answer for this equation. what I want

to do now is to but if statment so when there is no answer I will but

x=0 and y=o how I should do that I tried this but I want to know if

there is better answer:

if size(y,1) == 0

disp('yes')

tempL(7,3) = 0.0

tempL(8,3) = 0.0

else

disp('no')

tempL(7,3) = x

tempL(8,3) = y

end

#2; Wed, 07 May 2008 20:30:00 GMT

- Steven Lord wrote: