Curve won't graph using plot function

The curve for the equation y = ((sin(x)-x)/sin(x)) will not show up on the graph and I don't know why it is not working. The subplot is supposed to have both the curve described by y above and the line x = x. Here is my code:
x= 0:1;
y2= x;
y4= ((sin(x) - x) / sin(x));
subplot(1, 3, 3);
plot(x, y4, x, y2);

 Respuesta aceptada

Star Strider
Star Strider el 12 de Oct. de 2015
Editada: Star Strider el 12 de Oct. de 2015
There are two problems in your code. First, the colon (:) operator increments by default by 1, so ‘x’ is [0 1]. If you want a different step, you have to specify it. Second, you need to vectorise ‘y4’ by using element-wise division. (See Array vs. Matrix Operations for details.)
This works:
x= 0:0.1:1;
y2= x;
y4= ((sin(x) - x) ./ sin(x));
subplot(1, 3, 3);
plot(x, y4, x, y2);
Experiment with it to get the result you want.

1 comentario

Image Analyst
Image Analyst el 12 de Oct. de 2015
One might also look into the linspace() function - a good function to learn about.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Oct. de 2015

Comentada:

el 12 de Oct. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by