Using solve to solve an equation

조회 수: 1 (최근 30일)
Muthu
Muthu 2013년 1월 31일
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

답변 (2개)

bym
bym 2013년 1월 31일
편집: bym 2013년 2월 1일
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=============
subs(ans,{x1,y1,y2,d},[1,2,3,4])
ans =
-0.7321
2.7321
  댓글 수: 3
bym
bym 2013년 2월 1일
edited my answer...
Walter Roberson
Walter Roberson 2013년 2월 1일
Or
%set the variables and then,
syms x2
solve((x2-x1)^2+(y2-y1)^2-d,x2)

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2013년 1월 31일
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 "=="

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by