MATLAB Answers


Using solve to solve an equation

Asked by Muthu
on 31 Jan 2013

Hi everyone,

I am using 'solve' to solve an equation and I have to solve it for the variable x2. Below is the lines I have in my code.

                syms x2
                solve( d==(x2-x1)^2 + (y2-y1)^2)

But I get the following error message. "Conversion to double from sym is not possible."

I know that it returns symbolic variable which I have to convert to double I guess when I use x2. So I tried using double(x2)

 "DOUBLE cannot convert the input expression into a double
array. If the input expression contains a symbolic variable, use the VPA function instead."

as well as vpa(x2) as it suggested. But I still got the initial error. Any help would be appreciated. Thanks in advance



No products are associated with this question.

2 Answers

Answer by bym
on 31 Jan 2013
Edited by bym
on 1 Feb 2013

syms x1 x2 y1 y2 d
>> solve((x2-x1)^2+(y2-y1)^2-d,x2)
ans =
   x1 - (- y1^2 + 2*y1*y2 - y2^2 + d)^(1/2)
     x1 + (2*y1*y2 - y1^2 - y2^2 + d)^(1/2)

======== edit=============

ans =


on 31 Jan 2013


All the values are known except 'x2'. I need to access the value of 'x2' but I am not able to. Any further help is greatly appreciated.

on 1 Feb 2013

edited my answer...


%set the variables and then,
syms x2

Answer by Walter Roberson
on 31 Jan 2013

You are probably using a MATLAB version older than R2011b (I think it was), as the ability to use "==" in symbolic expressions is relatively new. proecsm shows the adjustment you can make to avoid using "=="


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!