how can I solve two equations with two unknown variable using matlab?

481 ビュー (過去 30 日間)
Avi
Avi 2018 年 4 月 17 日
コメント済み: Torsten 2018 年 4 月 18 日
I want to solve two equations with two unknown variables I have two equations (-x)*(x1 - x) + (r - y)*(y1 - y) = 0, (x1 - x)^2 + (y1 - y)^2 = z^2, where, x1,y1,r and z are known values. The values can be used as the inputs to the program.
what I tried is,
syms x y
eqns = [x^2 +y^2 - x*point_x - y*point_y + r*point_y - r*y == 0 ,...
(point_x - x)^2 + (point_y - y)^2 == length_tang^2];
vars = [x y];
[a,b] = solve(eqns,vars);
but it takes too much time and then gives no values.
  2 件のコメント
John D'Errico
John D'Errico 2018 年 4 月 17 日
編集済み: John D'Errico 2018 年 4 月 17 日
You say that x and y are unknowns. x1, y1, z are knowns.
(-x)*(x1 - x) + (r - y)*(y1 - y) = 0,
Then what is r? It is not an unknown. It is not known. Something in the middle perhaps? I also see an r1. Is it related to r? Is it known? Unknown? Quasi-known?
Avi
Avi 2018 年 4 月 17 日
sorry for that. I have edited the question. there is only one r and it is known.

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

採用された回答

John D'Errico
John D'Errico 2018 年 4 月 17 日
編集済み: John D'Errico 2018 年 4 月 17 日
point_x = 2;
point_y = 4;
length_tang = 1
r = 5;
syms x y
E = [(-x)*(point_x - x) + (r - y)*(point_y - y) == 0, (point_x - x)^2 + (point_y - y)^2 == length_tang^2];
S = solve(E,x,y)
S = 
  struct with fields:
      x: [2×1 sym]
      y: [2×1 sym]
S.x
ans =
   2
 6/5
S.y
ans =
    5
 17/5

Too slow? It came back virtually instantaneously.

timeit(@() solve(E,x,y))
ans =
      0.19394

0.2 seconds is too slow?

Note that it is probably possible for SOME sets of inputs, there is no real valued solution at all.

  2 件のコメント
Avi
Avi 2018 年 4 月 17 日
Thank you your answer works, but is slow as I have to solve it 51*61. Is there any way to increase the speed of the solution?
Torsten
Torsten 2018 年 4 月 18 日
Yes, you can get the general solution for point_x, point_y and r defined as "syms" and then substitute the 51*61 values for which you want to evaluate this solution.
help subs
Best wishes
Torsten.

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

その他の回答 (1 件)

Torsten
Torsten 2018 年 4 月 17 日

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by