Solve system of equations when plotting
Show older comments
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
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));
S.b1
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.
Answers (1)
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)]
symvar(eqns)
size(eqns)
S = solve(eqns)
S.b1
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])
1 Comment
Dhruv Srinivasan
on 10 Nov 2023
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!