# Matlab - graph of y=(sin(x)^2)/x^2

1. Nov 7, 2007

### sara_87

1. The problem statement, all variables and given/known data
i have to draw the graph of y=(sin(x)^2)/x^2 on matlab in interval [0,4pi]

2. Relevant equations

3. The attempt at a solution
i defined x and y.
>>x:[0:pi/4:4pi]
but i can't write the equation in matlab fprm...i dont know where to put the dots and brackets.
i tried:
>>sin(x).^2./x.^2
and i just got a straight line, then i tried:
>>sin(x.*x)./(x.*X)
and i also got a striaght line but when i put the function onto the graphics calculator it gives like a mountain shape and i think that's write.
so how do i type the function onto matlab to give the right graph?

2. Nov 7, 2007

### Maxwell

I don't have MATLAB near me right now, but I did notice two issues right away:

First off, this isn't going to work in MATLAB: "x:[0:pi/4:4pi]"

You should write it as: x = [0:pi/4:4*pi]

Secondly, this: sin(x.*x)./(x.*X) won't work because X is not the same as x in MATLAB. Try fixing those two issues and see if the plot works.

3. Nov 7, 2007

### sara_87

actually i dont have matlab infront of me either.. :(
but it's easy to fix the first broblem but for the second, i can change the X into an x but it still gives a straight line.
my problem is that i dont know how to write it in matlab because i dont know where to put the * or ^ or .
can u help me please because i have to typeit up tomorrow.
thank u v much :)

4. Nov 7, 2007

### marcusl

You did the periods just fine, and had the right idea. Correct the syntax and it will work fine. Try plotting more points.

x=[1:100]/100 * 4 * pi;
y = (sin(x) ./ x) .^2 ;
% Writing y this way is faster since you only square once.
plot(x,y)

5. Nov 7, 2007

### sara_87

i see but i cant do that because i dont want to type: (sinx)^2/x^2
i want: sin(x)^2/x^2
i.e. the squared in the numerator is just for x.