# Solving a symbolic equation in one or more variables

11 views (last 30 days)
Aleem Andrew on 20 Apr 2020
Commented: Aleem Andrew on 20 Apr 2020
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 on 20 Apr 2020
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.
Aleem Andrew on 20 Apr 2020

Tommy on 20 Apr 2020
>> 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]
Aleem Andrew on 20 Apr 2020