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

3 ビュー (過去 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 Center および File ExchangeAssumptions についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by