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

In summary, the conversation is about a student trying to graph the function y=(sin(x)^2)/x^2 on MATLAB in the interval [0,4pi]. The student is having trouble with the syntax and is seeking help from others to figure out where to place the dots, brackets, and other symbols in the equation. They have tried a few variations but have not been successful in getting the correct graph. One person suggests correcting the syntax and plotting more points to see if that works. The student also clarifies that they want to graph sin(x^2)/x^2, not (sinx)^2/x^2.
  • #1
sara_87
763
0

Homework Statement


i have to draw the graph of y=(sin(x)^2)/x^2 on MATLAB in interval [0,4pi]


Homework Equations




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 don't 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?
can someone please help me? :rolleyes:
 
Physics news on Phys.org
  • #2
sara_87 said:

Homework Statement


i have to draw the graph of y=(sin(x)^2)/x^2 on MATLAB in interval [0,4pi]


Homework Equations




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 don't 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?
can someone please help me? :rolleyes:

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
actually i don't 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 don't know how to write it in MATLAB because i don't know where to put the * or ^ or .
can u help me please because i have to typeit up tomorrow.
thank u v much :)
 
  • #4
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
i see but i can't do that because i don't 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... ;)
 
  • #6
sara_87 said:
i see but i can't do that because i don't want to type: (sinx)^2/x^2
i want: sin(x)^2/x^2
You mean sin(x^2)/x^2, then.

I have no idea about matlab, so can't give you any real help!
 

1. What is Matlab?

Matlab is a high-level programming language and interactive environment commonly used in scientific and engineering fields for data analysis, visualization, and numerical computations.

2. How do I plot the graph of y=(sin(x)^2)/x^2 in Matlab?

To plot this graph in Matlab, you can use the "plot" function. First, define the values of x (e.g. x = -10:0.1:10) and then calculate the corresponding values of y (e.g. y = (sin(x).^2)./x.^2). Finally, use the "plot" function to plot the graph: plot(x,y). You can also add labels and customize the appearance of the graph using additional functions.

3. What does the graph of y=(sin(x)^2)/x^2 represent?

The graph of y=(sin(x)^2)/x^2 represents the relationship between the sine function and the inverse square function. It represents the squared amplitude of the sine function divided by the squared distance from the origin.

4. How can I change the scale of the x-axis in the graph of y=(sin(x)^2)/x^2?

You can change the scale of the x-axis in Matlab using the "xlim" function. For example, if you want to change the x-axis scale to be between -5 and 5, you can use the command "xlim([-5, 5])". You can also use this function to customize the limits of the y-axis.

5. Can I save the graph of y=(sin(x)^2)/x^2 as an image in Matlab?

Yes, you can save the graph as an image in Matlab using the "saveas" function. After plotting the graph, use the command "saveas(gcf, 'filename.png')" to save the graph as a PNG file. You can also change the file format to JPEG, BMP, or other formats depending on your needs.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
821
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
994
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
696
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top