Azzera filtri
Azzera filtri

how to set condition to select conrrect answer from system solver

1 visualizzazione (ultimi 30 giorni)
Good day,
i have 2 equations (P&Q) and 2 unknowns (X & S22) T11,T12,L11,L12 are constants and have been predefined. My constants are all complex numbers.
I use the following codes to solve for X and S22. There are multiple answers, but only one is needed.
The answer must follow this condition. both real and imaginary part of (-1*ln(X)) must be positive, >0
how can i make an if else statement to choose the correct answer for X and S22?
T11=4.1346 + 3.7345i
T12=-4.8766 - 1.6522i
L11=4.8939 + 0.8988i
L12=-1.7834 + 9.5488i
syms X S22;
P = S22^2 - (T12*X-L12)/(T12*X-L12*X^2);
Q = T11-L11+S22*T12*(X^2-1)-S22^2 * (T11*X^2 - L11*X^2);
[T] = solve (P,Q);
[T] = [T.X T.S22];
R=-log(T)
I make the answer appear for R is
R =
[ - 0.000000000000000026838397425212912479593221696856*i - 0.0000000000000000044553700396231217159476263475639, - 3.141592653589793216666947094487*i - 0.0000000000000000064939931570843575531030608232192]
[ 1.7194165230724999144978781603064*i - 0.56180466790132359600931297362383, 1.4122192080422746081834964943096*i + 2.015002038802013782509142815176]
[ 0.000000000000000013430710296404625296312407777178 - 3.1415926535897932131520171172078*i, - 0.00000000000000001447014011626980507466109540703*i - 0.000000000000000022728630288299203359148628948126]
[ 0.5618046679013235835787182028784 - 1.7194165230724999123468743192883*i, - 1.4122192080422746321392716891471*i - 2.0150020388020136914626715842871]
[ 0.000000000000000015995872482245843105867536386529*i + 0.0000000000000000073618979275046328263580010857945, 0.00000000000000000033478977240226210079050384251655 - 0.000000000000000014716137012998175414759730464588*i]
[ 3.1415926535897932218435382191567*i - 0.0000000000000000039066434135407039322643553935171, 0.000000000000000010906166272636081414235041586457 - 3.1415926535897932266823788137464*i]
The answer that i want is R(5), the fifth row has the answer for -ln(X) to be both positive for the real and imaginary term. therefore the value in T(5) is the correct one
how can i set X to be the value in T(5,1), and S22 to be T(5,2)?
i have a long idea how to do it, which is if real and imaginary of R(1)>0, then X=R(1), else do nothing repeat again for R(2), R(3), R(4),R(5), R(6). but the problem is, what if the answer is more than 6 answers? the method i do assume it has 6 answers, if got more than 6, they wont be included in the if else, how how should i overcome this?
also, is it possible to make a warning if there are no answers that both real and imaginary is positive, or more than 1 answers both real and imaginary is positive?

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by