How to get Matlab to solve an equation involving log(x) and a constant*x on LHS and log of a vector on RHS?

syms cell
A=0.079;
B=6*10^-9;
C=3.5*10^-10;
R=37;
Is=260;
I=111;
solve('3.5*10^-10*(50-37)*cell-2.5*2*cell^3+19*2.5*cell^2+58*2.5*(cell-1)-2.5 - log((260/213)/(1-(260/213)))+log(6*10^-9)+0.079*(50-37)',cell)
# My function is
C*(50-R)*Cell - 2.5lnCell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
# here A, B and C are constants.. and I have to evaluate Cell from various values of I (* Please Note that I and R will be column vectors*), but this is the simplest form it can get solved to..
# I tried taylor series and got the simplified polynomial upto 3rd degree written in the code above and tried the solve function in Matlab,
# but it doesnt give a precise answer.
It gives me something like this
0.010445769111979284562103573703606*i - 3.1376696917728734352799890792042
11.729473052830051198402521143474 - 0.0039054714002454279122938908075595*i
0.014351240512224712474397464511166*i + 0.90819663894282223687746793573033
Please help me with this problem. Thank you

 Accepted Answer

A=0.079;
B=6*10^-9;
C=3.5*10^-10;
Is=260;
syms I Cl R
v = C*(50-R)*Cl - 2.5*log(Cl) - log(Is/I/(1-Is/I)) + log(B) + A*(50-R);
f2 = matlabFunction(solve(v,Cl))
% e.g.
out = f2([34 111],[37 23])

1 Comment

But this did not run for me..also now I need a loop to filter complex roots from real ones..out of 7-8 roots in one go..
ans =
596301325.91576234164749415177267
596301325.91576234164749415177148
0.00079574777275045645780180143342736
802746443.11830032332298137638464*i - 627820992.62821082772870512092314
- 802746443.11830032332298137638456*i - 627820992.62821082772870512092287
802746443.11830032332298137638455*i - 627820992.62821082772870512092287
0.00024589958501577221974263913391303 - 0.00075680110460163359394390295539747*i
- 0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
0.00075680110460163359394390295539747*i + 0.00024589958501577221974263913391303
- 802746443.11830032332298137638464*i - 627820992.62821082772870512092314
>> double(ans)
ans =
1.0e+008 *
5.9630
5.9630
0.0000
-6.2782 + 8.0275i
-6.2782 - 8.0275i
-6.2782 + 8.0275i
0.0000 - 0.0000i
-0.0000 - 0.0000i
-0.0000 + 0.0000i
0.0000 + 0.0000i
-6.2782 - 8.0275i
>> real(ans)
ans =
1.0e+008 *
5.9630
5.9630
0.0000
-6.2782
-6.2782
-6.2782
0.0000
-0.0000
-0.0000
0.0000
-6.2782
What I need is only one answer for one input of Intensity. That way I can process bulk data of intensity. also I need only real values and most of them above 10^8 range, how should I set a loop for that? my data ranges and can range from 100-1000s of points and I cant have 7-8 roots for every value.and sort manually.
Please suggest me a logic./ loop

Sign in to comment.

More Answers (1)

Filtering:
real_x = x(imag(x) == 0);
But going back to your original expression: you have
(Is/I)/((1-Is)/I)
where you indicate that "I" is a column vector.
If "I" was a scalar, then that would simplify to Is/(1-Is) [except when "I" was 0 or one of the infinities].
You have used algebraic notation such as 2.5lnCell in setting up your equation, so I have to ask whether you intend the expression to be calculated one value of "I" at a time (in which case that part would cancel), or are you intending the "/" operator there to signify MATLAB's mrdivide operator, which in the context would calculate a least-squares estimation ?
If the "I" values do indeed cancel then it becomes pointless to look for variations in Cell in terms of "I". On the other hand, the situation has a definite solution that can be expressed in terms of LambertW:
(5/2)*LambertW((2/5)*C*(-50+R)*exp((2/5)*ln*B+20*A-(2/5)*A*R)/(-Is/(-1+Is))^(2/5))/(C*(-50+R))

4 Comments

syms con
A=0.079;
B=6*10^-9;
C=3.5*10^-10;
R=37;
Is=260;
Intensity=8.682690623;
Hello Walter,
This is my modified code..Intensity is I ,i changed it because I got a suggestion that MATLAB might take it as an imaginary var itself. and as you mentioned since the last expression had log IS/I, and since IS is always greater than I. it was bound to generate negative log, and hence a complex root, I is a vector of values like 111, 8.6,8.4, 8.5 and so on till almost 0.
I intend to calculate one value of con for one value of Intensity each. and Lambertw would not be sufficient. I am indeed getting the o/p above mentioned. I need a little help with setting up any loop which will just give me one value of con for one value of I. but since i have used this solve (i guess) it is giving out all the possible roots.
syms con
A=0.079;
B=6*10^-9;
C=3.5*10^-10;
R=37;
Is=260;
Intensity=8.6
v=1+C*(50-37)*con+((C^2*(50-R)^2*con^2)/2)+((C^3*(50-R)^3*con^3)/6)+B*con^-2.5*(1-(Is/Intensity))-(Is/Intensity)*exp(-A*(50-R));
solve(v,con)
Thank you.
Please help me out with the edited code.
Thanks again
This is the algorithm I think I need to have
ence I wish to write a code where
1. It will store ans in an array
2.check each element for double and change datatype
2. check for real roots ( and not the real part of the complex roots as it has done for me above)
3. Check for positive roots
4. Check for repeated values
5. Except for the first value check for >10^8 range
apply all these filters and just get me one value.
With the revised equation, I get this, where k is an index in to the intensity and R vectors:
RootOf((7145833333*Intensity(k)*R(k)^3-893229166625000*Intensity(k)+53593749997500*Intensity(k)*R(k)-1071874999950*Intensity(k)*R(k)^2)*_Z^11+(-61250000000000000000*Intensity[k]*R(k)^2-153125000000000000000000*Intensity(k)+6125000000000000000000*Intensity(k)*R(k))*_Z^9-4550000000000000000000000000000*_Z^7*Intensity(k)+(1000000000000000000000000000000000000000*v*Intensity(k)-1000000000000000000000000000000000000000*Intensity(k)+260000000000000000000000000000000000000000*exp(-79/20+(79/1000)*R(k)))*_Z^5+1560000000000000000000000000000000-6000000000000000000000000000000*Intensity(k))^2
That is, con is the square of the zeros of the 11th degree polynomial given as RootOf(), with _Z being the variable that much be chosen so that the expression within RootOf() becomes 0.
*If* the values are such that floating point precision is not lost in any of the following expressions (snicker!) then this can be expressed in terms of the MATLAB numeric root finder as
con_values = roots([7145833333*Intensity(k)*(R(k)-50)^3, 0, -61250000000000000000*Intensity(k)*(R(k)-50)^2, 0, -4550000000000000000000000000000*Intensity(k), 0, 1000000000000000000000000000000000000000*(v*Intensity(k)-Intensity(k)+260*exp(-79/20+(79/1000)*R(k))), 0, 0, 0, 0, 1560000000000000000000000000000000 -6000000000000000000000000000000*Intensity(k)]) .^ 2;
However, it seems likely to me that you are in the range where double precision would not have enough resolution to calculate the values properly using roots()
Checking for real roots: those roots are precisely the roots for which the complex part is 0, so x(imag(x) == 0) *does* filter the vector x down to values that are not complex.
Walter, Can you also please tell me the syntax of the lambertw, i mean actually how to use it? I wanted to try it for the expression i solved by lambertw..my expression would be
exp(K1*X)+b*X^K2(1-K3)=K3*exp(K4)
and K1=3.5*10^-10*(50-R)
K2=-2.5
K3=(Is/Intensity)
K4=-0.079*(50-R)
Can you tell me how to solve this using lambertw?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!