Philip Cina
Philip Cina

Reputation: 5

Matlab will only plot points on my graph but wont connect them with any of the line types

I'm trying to make it plot this function which should be a straight line but it is only plotting points. I'm very new to Matlab and we haven't learned how to do this in class yet so I don't really know what I'm doing.

Code:

x = linspace(-30,30,31);  
y = sin(x)/x;  
plot(x,y,'-ro');  
axis([-30 30 -1 1])  
xlabel('x')  
ylabel('y')  
title('Philips Graph') 

Upvotes: 0

Views: 115

Answers (1)

Guto
Guto

Reputation: 541

The problem is you have only one point the the y matrix.

Try

y=sin(x)./x

This will make the division of every point (rdivide), not a matrix operation (mrdivide).

For your example, you also have the problem of the zero division in the middle point. You need to add eps to make the L´hospital's rule work. Using it properly it becomes

y = sin(x+eps)./(x+eps); 

Upvotes: 2

Related Questions