How to solve two variable equations using matlab?

6 ビュー (過去 30 日間)
Harith Karunaratne
Harith Karunaratne 2015 年 7 月 2 日
回答済み: Walter Roberson 2015 年 7 月 2 日
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 件のコメント
Harith Karunaratne
Harith Karunaratne 2015 年 7 月 2 日
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.
Torsten
Torsten 2015 年 7 月 2 日
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.

サインインしてコメントする。

回答 (2 件)

B.k Sumedha
B.k Sumedha 2015 年 7 月 2 日
It looks like MATLAB versions compatibility issue:

Walter Roberson
Walter Roberson 2015 年 7 月 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.

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by