Symbolic math toolbox: Obtaining real values from an expression of the form log(1-x)
2 views (last 30 days)
Alexander Schulze-Hulbe on 8 Apr 2021
I want to avoid complex numbers in my code. What is giving me trouble is an expression of the kind "log(1-x)" - I can't seem to convince MATLAB that "1-x" should be a positive value. If I'm not mistaken, MATLAB accepts that "1-x" is real, just not that I'd like it to be positive.
Please see my code snippet below.
clear all %clear all symbolic variables
syms m1 d_sigma epsilon1 n1 N_av T d V
d = d_sigma*(1-0.12*exp(-3*(epsilon1)*(1/T)));
%the values defined in this paragraph all have physical meaning
% and shouldn't be negative.
A1 = pi*N_av/(6*V)*n1*m1*(d)^3
B1 = log(A1)
test1 = isreal(B1) %returns true, but I'm actually interested in log(1-A1)
B2 = log(1-A1)
test2 = isreal(B2) %returns false - I think this is so because (1-A1) may be negative,
% meaning that complex numbers cannot be ruled out when computing log(1-A1)
assumeAlso(A1<1) %use this to prevent possibilty of taking natural log of a negative number
B3 = log(1-A1)
test3 = isreal(B3) %Still returns false - why?
Is there any way I can get log(1-A1) to be real?
Thanks in advance for your time.
Swatantra Mahato on 7 May 2021
As a workaround, you can define the exact expression as an assumption i.e.,
you can then check using the "isAlways" function in the Symbolic Math toolbox to perform the required checks
test3 = isAlways(in(B3,'real'))
I have brought this issue to the notice of our developers. They will investigate the matter further.
Hope this helps