Solving a symbolic equation in one or more variables

2 ビュー (過去 30 日間)
Aleem Andrew
Aleem Andrew 2020 年 4 月 20 日
コメント済み: Aleem Andrew 2020 年 4 月 20 日
When the following code is executed, the output is
ans =
Empty sym: 0-by-1
although b = i = yp = [1 90]
I get the same result when I let b = [1 90] or yp instead of r2p(i), although [1 90] = 1 ∠90 degrees = i. Does anyone have suggestions regarding how I should modify the code so that r2p(i) is understood to mean [1 90] (1 ∠90 degrees)? When r2p(i) is typed in the command window, the output is correct.
f = @(x,y) 2*x*y;
x = f(30,3)*2;
r2p = @(x) [abs(x) rad2deg(angle(x))]; % Rectangular -> Phasor
p2r = @(x) x(1)*exp(1i*deg2rad(x(2))); % Phasor -> Rectangular
pm = @(x,y) [x(1)*y(1) x(2)+y(2)]; % Phasor Multiply
pd = @(x,y) [x(1)/y(1) x(2)-y(2)]; % Phasor Divide
x = 3+4i;
xp = r2p(x);
yp = [1 90];
xptimesyp = pm(xp,yp);
xrtimesyr = p2r(xptimesyp);
Check = x * p2r(yp);
syms a b c
eqn = b==r2p(i);
solve(eqn,b)

採用された回答

Muthu
Muthu 2020 年 4 月 20 日
I just changed the last two lines of your code
eqn = [a b] ==r2p(i)
sol = solve(eqn)
To view the variable sol, you can call sol.a and sol.b to call system variables in sol -> [a b] which contains [1 90] respectively
Hope this helps.
-Muthu.
  1 件のコメント
Aleem Andrew
Aleem Andrew 2020 年 4 月 20 日
Thank you for your answer

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

その他の回答 (1 件)

Tommy
Tommy 2020 年 4 月 20 日
Your equation is
>> eqn
eqn =
[ b == 1, b == 90]
which has no solution.
You could specify that b should be a 1x2 vector:
r2p = @(x) [abs(x) rad2deg(angle(x))]; % Rectangular -> Phasor
syms b [1 2]
eqn = b==r2p(1i);
>> eqn
eqn =
[ b1 == 1, b2 == 90]
which gives
S = solve(eqn,b);
>> disp([S.b1 S.b2])
[ 1, 90]
  1 件のコメント
Aleem Andrew
Aleem Andrew 2020 年 4 月 20 日
Thank you for your answer

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by