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

6 visualizaciones (últimos 30 días)
kemal sen
kemal sen el 8 de Mzo. de 2015
Comentada: Walter Roberson el 16 de Nov. de 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 comentarios
Geoff Hayes
Geoff Hayes el 8 de Mzo. de 2015
Kemal - what is the code that you are using to plot your above y? What have you initialized x as?
kemal sen
kemal sen el 8 de Mzo. de 2015
Editada: Walter Roberson el 16 de Nov. de 2020
I used this
x=0:0.2:1;
y=(1-2*x)*log((1-x)/x) ;
plot(x,y)

Iniciar sesión para comentar.

Respuestas (2)

Giorgos Papakonstantinou
Giorgos Papakonstantinou el 8 de Mzo. de 2015
Editada: Giorgos Papakonstantinou el 8 de Mzo. de 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.
In your case you have to modify your equation:
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:
  1 comentario
kemal sen
kemal sen el 8 de Mzo. de 2015
Editada: kemal sen el 8 de Mzo. de 2015
Thank you very much..

Iniciar sesión para comentar.


D tk
D tk el 16 de Nov. de 2020
plot y=0.5*ln(pi*e),e is exp^1

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by