# Plotting (1-2*x)*log((1-x)/x)

34 views (last 30 days)
kemal sen on 8 Mar 2015
Commented: Walter Roberson on 16 Nov 2020
Hello!. I am very new to matlab and wanna know how can I plot
y=(1-2*x)*log((1-x)/x) function?
I tried to write it like that but it did not work as i expected.. It plots something else..
thanks..
and also why i cannot plot (1/x)? thanks.
##### 2 CommentsShowHide 1 older comment
kemal sen on 8 Mar 2015 I used this
x=0:0.2:1;
y=(1-2*x)*log((1-x)/x) ;
plot(x,y)

Giorgos Papakonstantinou on 8 Mar 2015
Edited: Giorgos Papakonstantinou on 8 Mar 2015
The problem occurs inside the log parenthesis. The syntax that you have used tells Matlab to solve the equation:
x = B/A
for x. Check the documentation for mrdivide to get more a thorough explanation.
If you want to do element-wise arithmetic operations (division, power, etc.) then you have to use . before each operation. Look for more information here.
y=(1-2.*x).*log((1-x)./x)
Here the log function computes the natural logarithm.
or
y=(1-2.*x).*log10((1-x)./x)
Here the log10 function computes the logarithm when the base is 10
For example if:
x=0:0.02:1;
y=(1-2*x).*log((1-x)./x) ;
plot(x,y)
the result is: kemal sen on 8 Mar 2015
Thank you very much..

D tk on 16 Nov 2020
plot y=0.5*ln(pi*e),e is exp^1
Walter Roberson on 16 Nov 2020
plot(0.5*log(pi*exp(1)), 'r*') 