How to solve two variable equations using matlab?

I have three equations need to solve using Matlab. i tried this code
solve( rs1==a01+a11*xp+a21*yp+a31*xp*yp, rs2==a02+a12*xp+a22*yp+a32*xp*yp,rs3==a03+a13*xp+a23*yp+a33*xp*yp );
but i cant get xp and xy values and this error "Error using mupadengine/feval (line 157) MuPAD error: Error: Invalid variable to solve for. [solve]" comes. what is the way to solve this? and im using 2014a

7 Comments

Which version of matlab your using?
First of all, use = instead of ==. Second, give MATLAB, that you want to solve for xp and yp.
B.k Sumedha - im using 2014a
i did it again and now it shows this;
Warning: 1 equations in 0 variables. > In C:\Program Files\MATLAB\R2014a\toolbox\symbolic\symbolic\symengine.p>symengine at 56 In mupadengine.mupadengine>mupadengine.evalin at 97 In mupadengine.mupadengine>mupadengine.feval at 150 In solve at 170 Error using mupadengine/feval (line 157) MuPAD error: Error: A variable to solve for is required. [solve]
Error in solve (line 170) sol = eng.feval('symobj::solvefull',eqns,vars);
Three equations for two variables ?
I doubt that "solve" can handle overdetermined systems of equations.
Best wishes
Torsten.
i checked using two equations which gave me an answer that is not possible in any rate and i think three equation makes things easier in finding two variables.
No. You can easily calculate xp and yp from the first two equations, but this solution will in general not satisfy the third equation.
Best wishes
Torsten.

Sign in to comment.

Answers (2)

No, three equations in two variables makes it harder to solve, not easier.
We need to know which of those names you give are "syms" and which are numeric, and we need to know whether any of the numeric variables are non-integral.
The first two equations together define xp and yp in terms of the roots of a quadratic equation. There are therefore exactly two closed-form solutions, to the limits of round-off.
The solution pairs can be substituted into the third equation, producing a moderately long result that includes sqrt() in more than one place. Chances that an evaluation given floating point numbers would happen to exactly equal rs3 are small.
Use
syms A01 A02 A11 A12 A21 A22 A31 A32 Rs1 Rs2 xp yp
sols = solve(Rs1 == A31*xp*yp+A11*xp+A21*yp+A01, Rs2 = A32*xp*yp+A12*xp+A22*yp+A02], [xp, yp]);
xvals = double(subs(sols.X, {A01 A02 A11 A12 A21 A22 A31 A32 Rs1 Rs2}, {a01 a02 a11 a12 a21 a22 a31 a32 rs1 rs2}));
yvals = double(subs(sols.Y, {A01 A02 A11 A12 A21 A22 A31 A32 Rs1 Rs2}, {a01 a02 a11 a12 a21 a22 a31 a32 rs1 rs2}));
now use xvals(1) with yvals(1), or xvals(2) with yvals(2). And if neither of them are what you were expecting then your expectations would be wrong for those formulae.

Asked:

on 2 Jul 2015

Answered:

on 2 Jul 2015

Community Treasure Hunt

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

Start Hunting!