Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Nov 7, 2007 #1
    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.
    but i can't write the equation in matlab fprm...i dont know where to put the dots and brackets.
    i tried:
    and i just got a straight line, then i tried:
    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?
    can someone please help me? :rolleyes:
  2. jcsd
  3. Nov 7, 2007 #2
    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.
  4. Nov 7, 2007 #3
    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 :)
  5. Nov 7, 2007 #4


    User Avatar
    Science Advisor
    Gold Member

    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.
  6. Nov 7, 2007 #5
    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.

    help please... ;)
  7. Nov 7, 2007 #6


    User Avatar
    Staff Emeritus
    Science Advisor

    You mean sin(x^2)/x^2, then.

    I have no idea about matlab, so can't give you any real help!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook