# how to find unknown within equation having unknown

1 view (last 30 days)
hsnHkl on 22 Dec 2021
Edited: John D'Errico on 22 Dec 2021
I have a equation which includes 2 matrix and 1 unknown I want to calculate the unknown for each row and save the results as another matrix for each term my equation is R/X=( 0.8*log(L*X/10e-06)+33 )
R is 132x1 matrix (known)
L is 132x1 matrix (known)
I want to find X matrix

Star Strider on 22 Dec 2021
I have no idea if this actually has a robust (and mathematically correct) solution.
It is always appropriate to experiment, so I am doing that here —
RLX_fcn = @(X,R,L) R./X - ( 0.8*log(L.*X/10e-06)+33 )
RLX_fcn = function_handle with value:
@(X,R,L)R./X-(0.8*log(L.*X/10e-06)+33)
R = randn(10,1);
L = randn(10,1);
X0 = rand(size(R))
X0 = 10×1
0.1263 0.0376 0.5791 0.9550 0.3068 0.1994 0.0835 0.2704 0.8998 0.1432
[Xv,fv] = fsolve(@(X)RLX_fcn(X,R,L), X0)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
Xv =
0.0112 - 0.0007i 0.0033 + 0.0002i -0.0156 + 0.0010i -0.0161 + 0.0000i 0.0074 - 0.0005i -0.0114 + 0.0000i -0.0041 + 0.0000i 0.0328 - 0.0021i -0.0150 + 0.0010i 0.0236 - 0.0000i
fv =
1.0e-14 * 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0444i 0.7105 + 0.0098i 0.0000 + 0.0000i -0.7105 + 0.0018i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0444i 0.0000 + 0.0000i
Experiment further with the correct vectors.
.
John D'Errico on 22 Dec 2021
Actually, no that is not correct, and it has an analytical solution, in terms of the wrightOmega function. It is sort of a cousin to the Lambert W, and probably about as well known.

John D'Errico on 22 Dec 2021
Edited: John D'Errico on 22 Dec 2021
R and L are known, with X being an unknown.
syms X L R
Xsol = solve(R/X==( 0.8*log(L*X/10e-06)+33),X)
Xsol = The script w there is the wrightOmega function in MATLAB. Most people don't seem to know it even exists, but it does, as a special function, essentially to solve this exact class of problem..
help wrightOmega
--- help for double/wrightOmega --- WRIGHTOMEGA Wright omega function. W = WRIGHTOMEGA(X) is a solution of the equation Y + log(Y) = X. Reference:  Corless, R. M. and Jeffrey, D. J. "The Wright omega Function." In Artificial Intelligence, Automated Reasoning, and Symbolic Computation (Ed. J. Calmet, B. Benhamou, O. Caprotti, L. Henocque and V. Sorge). Berlin: Springer-Verlag, pp. 76-89, 2002. Documentation for double/wrightOmega doc double/wrightOmega Other functions named wrightOmega single/wrightOmega sym/wrightOmega
So now you can form the solution simply enough, as...
Xfun = matlabFunction(Xsol)
Xfun = function_handle with value:
@(L,R)(R.*(5.0./4.0))./wrightOmega(-log(1.0./(L.*R.*1.25e+5))+1.65e+2./4.0)
So Xfun is a function of two variables, L and R. We can use this as follows:
Xfun(1,3)
ans = 0.0747
If L and R are vectors, it will still work.
Xfun([1 2 3],[4 5 6])
ans = 1×3
0.0991 0.1217 0.1444

R2017b

### Community Treasure Hunt

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

Start Hunting!