Effacer les filtres
Effacer les filtres

Solve system of equations when plotting

1 vue (au cours des 30 derniers jours)
Dhruv Srinivasan
Dhruv Srinivasan le 13 Oct 2023
Hi,
I'm trying to solve a system of equations below symbolically. The challenge is that it only works symbolically if variables 'phi' and 'psi' are defined with numeric values as opposed to symbolic variables (this makes sense, since when 'phi' and 'psi' are defined, the system becomes a system of 5 equations and 5 unknowns as opposed to 5 equations and 7 unknowns.
This works:
t = 1;
t2 = 1;
k = 1;
k2 = 1;
a1 = 1;
phi = pi/3;
psi = pi/6;
syms a2 a3 b1 b2 b3
S = solve(b1 == a1*t + a2*1j*k,b2 == a1*1j*k + a2*t, b3==a3*t2 + b2*1j*k2*exp(1j*phi), ...
a2 == exp(1j*phi)*(b2*t2*exp(1j*phi)+a3*1j*k2), a3 == b3*exp(2j*psi));
S.b1
ans = 
This does not
t = 1;
t2 = 1;
k = 1;
k2 = 1;
a1 = 1;
syms a2 a3 b1 b2 b3 phi psi
S = solve(b1 == a1*t + a2*1j*k,b2 == a1*1j*k + a2*t, b3==a3*t2 + b2*1j*k2*exp(1j*phi), ...
a2 == exp(1j*phi)*(b2*t2*exp(1j*phi)+a3*1j*k2), a3 == b3*exp(2j*psi));
Warning: Unable to find explicit solution. For options, see help.
S.b1
ans = Empty sym: 0-by-1
However, I'd like to try to plot each variable (say, b1) with respect to phi and psi changing. This means that I can't define it before hand. I've hit a bit of a roadblock as to how to do this.

Réponses (1)

Walter Roberson
Walter Roberson le 13 Oct 2023
t = 1;
t2 = 1;
k = 1;
k2 = 1;
a1 = 1;
syms a2 a3 b1 b2 b3 phi psi
eqns = [b1 == a1*t + a2*1j*k,b2 == a1*1j*k + a2*t, b3==a3*t2 + b2*1j*k2*exp(1j*phi), ...
a2 == exp(1j*phi)*(b2*t2*exp(1j*phi)+a3*1j*k2), a3 == b3*exp(2j*psi)]
eqns = 
symvar(eqns)
ans = 
size(eqns)
ans = 1×2
1 5
S = solve(eqns)
Warning: Unable to find explicit solution. For options, see help.
S = struct with fields:
b1: [0×1 sym] b2: [0×1 sym] b3: [0×1 sym] phi: [0×1 sym] psi: [0×1 sym]
S.b1
ans = Empty sym: 0-by-1
You have 5 equations in 6 unknowns. solve() is going to guess which variables to solve for
S2 = solve(eqns, [a2 a3 b1 b2 b3])
S2 = struct with fields:
a2: -(exp(phi*2i)*1i - exp(phi*2i)*exp(psi*2i)*2i)/(exp(phi*2i) + exp(psi*2i) - 2*exp(phi*2i)*exp(psi*2i) - 1) a3: (exp(phi*1i)*exp(psi*2i))/(exp(phi*2i) + exp(psi*2i) - 2*exp(phi*2i)*exp(psi*2i) - 1) b1: (2*exp(phi*2i) + exp(psi*2i) - 4*exp(phi*2i)*exp(psi*2i) - 1)/(exp(phi*2i) + exp(psi*2i) - 2*exp(phi*2i)*exp(psi*2i) - 1) b2: (exp(psi*2i)*1i - 1i)/(exp(phi*2i) + exp(psi*2i) - 2*exp(phi*2i)*exp(psi*2i) - 1) b3: exp(phi*1i)/(exp(phi*2i) + exp(psi*2i) - 2*exp(phi*2i)*exp(psi*2i) - 1)
  1 commentaire
Dhruv Srinivasan
Dhruv Srinivasan le 10 Nov 2023
Thank you so much for your help!

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by