Sunday

August 28, 2016
Posted by **Lee** on Wednesday, July 20, 2011 at 5:28pm.

Consider the following two equations:

x^2 + y^2 = 42

x + 3y + 2y^2 = 6

Define a symbolic equation for each, and solve it by using MATLAB's symbolic capability. Could you solve these equations by using matrices? Try this problem twice, once using only integers in your equation definitions and once using floating-point numbers (those with decimal points). how do your results vary? Check the workspace window to determine weather the results are still symbolic.

I think that I may be doing something wrong because when I wrote out my code and ran it I got the same exact results when I tried using integers and when I included decimal points. I was hoping someone could explain to me what I'm doing wrong because I guess I'm suppose to get different results.

>> disp('No you could not solve this problem usign matrices.')

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)

No you could not solve this problem usign matrices.

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

I was expecting my results to differ and to get the exact result when used integers and a estimate when I used digits with numbers. Do you know why this may have occurred? My friend ran the exact code on a much older version of MATLAB and produced the expected results, the exact answer were he entered digits

one=sym('x^2+y^2-42');

two=sym('x+3*y+2*y^2-6');

[x,y]=solve(one,two)

and a rounded answer when he didn't

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)

we both can't seem to figure out why I'm not getting the same results when I run the same exact program in MATLAB

- Computer Science - MATLAB -
**MathMate**, Wednesday, July 20, 2011 at 9:01pmThe answers are correct (4 sets).

Not sure how to explain the differences.

You could try

x=sym['x'];

y=sym['y'];

to force x and y to be symbolic variables

before defining one and two. - THIS WHAT MY FRIEND GOT -
**THIS WHAT MY FRIEND GOT**, Wednesday, July 20, 2011 at 10:47pmx =

[ 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)]

and this is what I was expecting to get when I ran it in matlab with digits and not floating point numbers but i dont - Computer Science - MATLAB -
**THIS WHAT MY FRIEND GOT**, Wednesday, July 20, 2011 at 11:09pmI tried what you mentioned above and got the same results, an estimated value and not the above, my friend is also using a really old version of matlab

- Computer Science - MATLAB -
**MathMate**, Thursday, July 21, 2011 at 7:44amThis is strange.

I checked the symbolic answers with a different software and I got at one time the same answer as your friend, with i in the answers and very complicated expressions, i.e. symbolic answers.

After that, I get the numeric answers as you've got. I do not know if you have substituted the numeric answers into the equations to check. I did it for one case, and I got 10^-7 as residues, which is correct.

I will see if I can check with the version of Matlab at university and find out what it gives. - Computer Science - MATLAB -
**MathMate**, Thursday, July 21, 2011 at 8:46amAs a follow-up, here are some additional information.

If you note that the second equation is linear in x, i.e.

x + 3y + 2y^2 = 6 ...(2)

can be rewritten as

x = -3y + -2y^2 + 6

which can then be substituted int the first equation

x^2 + y^2 = 42 ...(1)

to become

(-3y + -2y^2 + 6 )^2 + y^2 = 42

which is a quartic and soluble symbolically.

The results are precisely what your friend got directly from an older version of Matlab.

The values of y can then be substituted into the original equations (1) and (2) to solve for x.

However, it is important to substitute these pairs of answers into both equations to make sure that they work, which is where Matlab comes in handy.

So if Matlab does not give you the symbolic answers directly, you can still use Matlab to get the symbolic answers, with a little more elbow grease.

It is possible that Matlab now defaults to answers by numerical methods, and using Newton's approximation in 2-d, it is possible to obtain answers of indefinite accuracy.

Give it a try! - Computer Science - MATLAB -
**MathMate**, Thursday, July 21, 2011 at 10:23pmHave you tried the muPad package? It is built into the Matlab and is a package for symbolic math.

I tried your code on Matlab version 2010b and it gives only numerical answers as you got.

I believe you need to use muPad or a special interpreting command if you want to stay in Matlab command line.