Solving system of equations

14 ビュー (過去 30 日間)
Mehmet Özesenlik
Mehmet Özesenlik 2020 年 8 月 12 日
コメント済み: Walter Roberson 2020 年 8 月 17 日
Hi there,
I have multiple equations which determine the values in a circuit. I'm trying get the values which satisfy these equations (maybe even with conditions like nonnegative circuit values).
This is my code but I get these errors:
Error using symengine
Input arguments must be convertible to floating-point numbers.
Error in sym/privBinaryOp (line 1030)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in sym/max (line 78)
C = privBinaryOp(X, Y, 'symobj::zipWithImplicitExpansion', 'symobj::maxComplex');
Error in Class_E (line 4)
eqn2 = C1==max(0, 1/(2*pi*RFfreq*R_L)*K_C-1.088E-12);
I really appreciate any help you can provide.
Best,
Safak
syms RFfreq R_L V_DD P_out C1 C2 L1 L2 K_P K_C K_X K_L
eqn1 = R_L==V_DD*V_DD/P_out*K_P;
eqn2 = C1==max(0, 1/(2*pi*RFfreq*R_L)*K_C-1.088E-12); %take 0 or what the right side equatates to (if nonzero)
eqn3 = C2==C_0;
eqn4 = L2==L_0+R_L/(2*pi*RFfreq)*K_X;
eqn5 = L1==R_L/(2*PI*RFfreq)*K_L;
eqn6 = K_L==1E6;
eqn7 = K_C==0.1836;
eqn8 = K_P==0.5768;
eqn9 = K_X==1.152;
eqn10 = V_DD==17;
eqn11 = P_out==15;
eqn12 = RFfreq==3.5E9;
eqn13 = C_0==1E-09;
eqn14 = L_0==1/(2*PI*RFfreq)^2/C_0;
eqns = [eqn1 eqn2 eqn3 eqn4 eqn5 eqn6 eqn7 eqn8 eqn9 eqn10 eqn11 eqn12];
sol=solve(eqns)
  3 件のコメント
Mehmet Özesenlik
Mehmet Özesenlik 2020 年 8 月 12 日
Yes, I could just use pi there, right? Code is from Keysight's ADS. That's why it is spelled this way.
Mehmet Özesenlik
Mehmet Özesenlik 2020 年 8 月 12 日
I forgot to include these:
eqn13 = C_0==1E-09;
eqn14 = L_0==1/(2*PI*RFfreq)^2/C_0;

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 12 日
Q = @(v) sym(v);
PI = Q(pi);
symmax = @(A,B) piecewise(A<=B, A, B);
syms RFfreq R_L V_DD P_out C1 C2 L1 L2 K_P K_C K_X K_L
syms C_0 L_0
eqn1 = R_L==V_DD*V_DD/P_out*K_P;
eqn2 = C1==symmax(0, 1/(2*PI*RFfreq*R_L)*K_C-Q(1.088E-12)); %take 0 or what the right side equatates to (if nonzero)
eqn3 = C2==C_0;
eqn4 = L2==L_0+R_L/(2*PI*RFfreq)*K_X;
eqn5 = L1==R_L/(2*PI*RFfreq)*K_L;
eqn6 = K_L==Q(1E6);
eqn7 = K_C==Q(0.1836);
eqn8 = K_P==Q(0.5768);
eqn9 = K_X==Q(1.152);
eqn10 = V_DD==Q(17);
eqn11 = P_out==Q(15);
eqn12 = RFfreq==Q(3.5E9);
eqns = [eqn1 eqn2 eqn3 eqn4 eqn5 eqn6 eqn7 eqn8 eqn9 eqn10 eqn11 eqn12];
sol = solve(eqns, [C1, C2, K_C, K_L, K_P, K_X, L1, L2, P_out, RFfreq, R_L, V_DD]);
sol will be a mix of constant values, together with the variables C_0 and L_0
  4 件のコメント
Mehmet Özesenlik
Mehmet Özesenlik 2020 年 8 月 17 日
Wow, thank you for this extensive and deep explanation!
Would you mind to share the script when C_0 and L_0 are given like here?
eqn13 = C_0==1E-09;
eqn14 = L_0==1/(2*PI*RFfreq)^2/C_0;
Walter Roberson
Walter Roberson 2020 年 8 月 17 日
Q = @(v) sym(v);
PI = Q(pi);
symmax = @(A,B) piecewise(A<=B, A, B);
syms RFfreq R_L V_DD P_out C1 C2 L1 L2 K_P K_C K_X K_L
syms C_0 L_0
eqn1 = R_L==V_DD*V_DD/P_out*K_P;
eqn2 = C1==symmax(0, 1/(2*PI*RFfreq*R_L)*K_C-Q(1.088E-12)); %take 0 or what the right side equatates to (if nonzero)
eqn3 = C2==C_0;
eqn4 = L2==L_0+R_L/(2*PI*RFfreq)*K_X;
eqn5 = L1==R_L/(2*PI*RFfreq)*K_L;
eqn6 = K_L==Q(1E6);
eqn7 = K_C==Q(0.1836);
eqn8 = K_P==Q(0.5768);
eqn9 = K_X==Q(1.152);
eqn10 = V_DD==Q(17);
eqn11 = P_out==Q(15);
eqn12 = RFfreq==Q(3.5E9);
eqn13 = C_0==Q(1E-09);
eqn14 = L_0==1/(2*PI*RFfreq)^2/C_0;
eqns = [eqn1 eqn2 eqn3 eqn4 eqn5 eqn6 eqn7 eqn8 eqn9 eqn10 eqn11 eqn12];
eqns = subs(eqns,lhs(eqn14),rhs(eqn14));
eqns = subs(eqns,lhs(eqn13),rhs(eqn13));
vars = [C1, C2, K_C, K_L, K_P, K_X, L1, L2, P_out, RFfreq, R_L, V_DD];
sol = solve(eqns, vars);
sol.(char(lhs(eqn13))) = rhs(eqn13);
sol.(char(lhs(eqn14))) = subs(rhs(eqn14),sol);

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

その他の回答 (1 件)

hosein Javan
hosein Javan 2020 年 8 月 12 日
編集済み: hosein Javan 2020 年 8 月 12 日
you must first define the unknowns in your system of equations. it seems you have 12 equations and therefore you must have 12 unknowns. if not 12 unknowns then reduce the number of equations to the number of unknowns. then correct the final line:
% define your unknowns in a vector like this x = [x1, x2, ..., x12]
sol=solve(eqns,x)
also eqn2 has a problem. it is defined in a way to compute the max of an unknown symbolic type and a real number 0. I suggest you solve the equations two times for each one of them and see which solution meets the condition.
  4 件のコメント
Mehmet Özesenlik
Mehmet Özesenlik 2020 年 8 月 12 日
What is the difference between using a system of equations and this way?
hosein Javan
hosein Javan 2020 年 8 月 12 日
this way is way more efficient. you were using symbolic math toolbox which is dedicated for symbolic equations that are not ordinarily simple to solve or simplify by hand. furthermore your case was not a system of equations containing unknowns depending on each other. has the problem been solved yet?

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

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by