Solving a symbolic equation in one or more variables

조회 수: 8 (최근 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개)

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]

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by