Symbolic math toolbox: Obtaining real values from an expression of the form log(1-x)

조회 수: 4 (최근 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
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
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 CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by