Graphing a sin function - graph not appearing?

I'm trying to plot a sin function, but when the plot window shows up, nothing appears within it.
The function I'm trying to plot is y(x) = sin(2x)/(2x). Here's what I'm doing to get the graph ready:
1. x = 0:pi/100:2*pi;
2. y = sin(2*x)/(2*x);
3. plot(x,y);
I've changed the order of x and y in plot(), but that hasn't done anything for me.
What can I do to fix this?

4 comentarios

Bikiran Das
Bikiran Das el 5 de Sept. de 2016
x = 0:pi./100:2*pi; y = sin(2*x)./(2*x); plot(x,y);
USe this code
Joshua Kahn
Joshua Kahn el 5 de Sept. de 2016
Thank you so much, this caused the graph to appear!
Just out of curiosity, why is the addition of the "." after pi and after sin(2*x) required to fix this?
Bikiran Das
Bikiran Das el 5 de Sept. de 2016
during division of float values use of a '.' is recommended
The '.' is used for element wise matrix multiplication/division. It is not actually needed after the pi in the first line of code, but is required in the second.
y1 = sin(2*x) % produces a matrix with 201 elements
y2 = 2*x %produces matrix with 201 elements
Now you need to do an element wise division between y1 and y2. For this you need to use the './' operator rather than a single '/', which is the matrix division operator

Iniciar sesión para comentar.

 Respuesta aceptada

Bikiran Das
Bikiran Das el 5 de Sept. de 2016

0 votos

x = 0:pi./100:2*pi; y = sin(2*x)./(2*x); plot(x,y);
Use this code
during division of float values use of a '.' is recommended

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 5 de Sept. de 2016

Comentada:

el 6 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by