필터 지우기
필터 지우기

Solving Systems of Equations Using the Solve Function - Not Returning Exact Answer as Suppose to When Using Integers

조회 수: 2 (최근 30일)
I'm using the latest version of MATLAB and I entered a code that stresses that MATLAB is suppose to reutrn exact results when you enter expressions or equations with integers (i.e. 3) into the solve function and an estimated answers when you enter expressions or equations that contain non-integers (i.e. 3.0).
I was trying to solve the following systems of equations with MATLAB with two codes, one that used integers and one that didn't, to show that to get both results, a estimated answer and a exact answer.
x^2+y^2=42
x+3y+2y^2=6
Below is my code
>> syms x y
one=sym('x^2+y^2-42');
two=sym('x+3*y+2*y^2-6');
[x,y]=solve(one, two)
one=sym('x^2.0+y^2.0-42.0');
two=sym('x+3.0*y+2.0*y^2.0-6.0');
[x,y]=solve(one,two)
x =
-6.2161908711674029137999766546085
6.4782037201238076694174751205659
6.3321946913754454971273459117746
-5.594207540331850252744844377732
y =
1.8327495882457713513416277757555
-0.18131894709064188368251606877471
-1.3796051574695662000556283784362
-3.2718254836855632676034833285446
x =
-6.2161908711674029137999766546085
6.4782037201238076694174751205659
6.3321946913754454971273459117746
-5.594207540331850252744844377732
y =
1.8327495882457713513416277757555
-0.18131894709064188368251606877471
-1.3796051574695662000556283784362
-3.2718254836855632676034833285446
As you can see MATLAB is not returning both an estimated set of solutions and a exact set of solutions. Instead it's just returning two sets of estimated solutions, which is not what I was expecting. Oddly enough when I get my friend to copy and paste my code into his older version of MATLAB he got the exact answer
x =
[ 33/4-1/4*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-1/4*6^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)-301*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+9*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)-2*(-3/4+1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+1/12*6^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)-301*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+9*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2))^2]
[ 33/4-1/4*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+1/4*6^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)-301*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+9*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)-2*(-3/4+1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-1/12*6^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)-301*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+9*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2))^2]
[ 33/4+1/4*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-1/4*(-(-330*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+6*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)+1806*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+54*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)-2*(-3/4-1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+1/12*(-(-330*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+6*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)+1806*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+54*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2))^2]
[ 33/4+1/4*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+1/4*(-(-330*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+6*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)+1806*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+54*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)-2*(-3/4-1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-1/12*(-(-330*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+6*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)+1806*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+54*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2))^2]
y =
[ -3/4+1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+1/12*6^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)-301*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+9*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)]
[ -3/4+1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-1/12*6^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)-301*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+9*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)]
[ -3/4-1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+1/12*(-(-330*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+6*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)+1806*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+54*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)]
[ -3/4-1/12*3^(1/2)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)-1/12*(-(-330*(2033+18*i*71413^(1/2))^(1/3)*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+6*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)*(2033+18*i*71413^(1/2))^(2/3)+1806*((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2)+54*3^(1/2)*(2033+18*i*71413^(1/2))^(1/3))/(2033+18*i*71413^(1/2))^(1/3)/((55*(2033+18*i*71413^(1/2))^(1/3)+2*(2033+18*i*71413^(1/2))^(2/3)+602)/(2033+18*i*71413^(1/2))^(1/3))^(1/2))^(1/2)]
I don't understand why I can't get MATLAB to give me the exact results as well. I was hoping someone could tell me what I'm doing wrong and how I could get MATLAB to return the exact results above like it's suppose to when I enter integer values in the solve function. If you have no clue could you at least let run my code and let me know what results you get. I have MATLAB 7.12.0(R2011a). My friend that got the exact results using MATLAB R13 (v6.5). I also had someone else run my code in MATLAB 2010b and they got an estimated answer as I did.
I'm really confused as to what I'm doing wrong. THANKS for any help!!!

답변 (3개)

Walter Roberson
Walter Roberson 2011년 7월 24일
The symbolic toolkit in R13 was based upon Maple. When I try with a relatively current version of Maple, without any difficulty I get the solution expressed in terms of the roots of a quartic, which are then easily convertible to expressions equal to the long ones your friend got.
Current versions of the symbolic toolkit are based upon MuPad. I do not have that software to test against. Generally speaking, when MuPad is asked to solve() something that it is not able to find exact roots for, it will do a numeric solution instead. I have noticed from what other people have posted that MuPad is apparently weaker at solving polynomials.
I would suggest using evalin(symengine) to directly call upon MuPad's solve() routine instead of the interface routine that you are invoking now. MuPad's solve() routine accepts a number of options that you cannot pass through the MATLAB interface. One of the things you might wish to experiment with is the maximum degree of polynomial that MuPad will express in terms of exact solutions. I do not know if it will help in this particular case.
  댓글 수: 2
Dylan
Dylan 2011년 7월 24일
I'm unfamiliar with the evalin function
>> one=evalin(sym('x^2.0+y^2.0-42.0'))
two=evalin(sym('x+3.0*y+2.0*y^2.0-6.0'))
??? Undefined function or method 'evalin' for input arguments of type 'sym'.
Walter Roberson
Walter Roberson 2011년 7월 24일
http://www.mathworks.com/help/toolbox/symbolic/evalin.html
http://www.mathworks.com/help/toolbox/mupad/stdlib/solve.html
evalin(symengine, 'solve([x^2+y^2-42,x+3*y+2*y^2-6],[x y],MaxDegree=4)')

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


Dylan
Dylan 2011년 7월 24일
thanks for your answer ^_^ the evalin function doesn't accept symbolic inputs i guess so I'm unsure on how to proceed

Dylan
Dylan 2011년 7월 25일
anyone?
  댓글 수: 3
Christopher Creutzig
Christopher Creutzig 2011년 9월 8일
You can often avoid the char problems by using feval instead:
eqs = sym('[x^2+y^2-42,x+3*y+2*y^2-6]');
feval(symengine, 'solve', eqs, 'MaxDegree=4')
Walter Roberson
Walter Roberson 2011년 9월 8일
Thanks, Christopher. I was remembering a day or two ago (in response to a different question) that I had seen people use feval() for this, but the proper invocation escaped me at the time.

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

카테고리

Help CenterFile Exchange에서 Utilities for the Solver에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by