Symbolic math toolbox: Obtaining real values from an expression of the form log(1-x)
1 次查看(过去 30 天)
显示 更早的评论
Hi All
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)));
assume(m1,'real')
assume(d_sigma,'real')
assume(epsilon1,'real')
assume(n1,'real')
assume(N_av,'real')
assume(T,'real')
assumeAlso(d,'real')
assume(V,'real')
%the values defined in this paragraph all have physical meaning
% and shouldn't be negative.
assumeAlso(m1,'positive')
assumeAlso(d_sigma,'positive')
assumeAlso(epsilon1,'positive')
assumeAlso(n1,'positive')
assumeAlso(N_av,'positive')
assumeAlso(T,'positive')
assumeAlso(d,'positive')
assumeAlso(V,'positive')
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.
Kind regards
Alex
1 个评论
Paul
2021-4-10
isreal() is not on the list of functions for the Symbolic Math Toolbox, so it's not clear what to expect when using it.
采纳的回答
Swatantra Mahato
2021-5-7
Hi Alexander,
As a workaround, you can define the exact expression as an assumption i.e.,
assumeAlso((1-A1)>0);
you can then check using the "isAlways" function in the Symbolic Math toolbox to perform the required checks
test3 = isAlways(in(B3,'real'))
test3 =
logical
1
I have brought this issue to the notice of our developers. They will investigate the matter further.
Hope this helps
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!