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

  • Context: MATLAB 
  • Thread starter Thread starter sara_87
  • Start date Start date
  • Tags Tags
    Graph Matlab
Click For Summary

Discussion Overview

The discussion revolves around how to correctly plot the function y=(sin(x)^2)/x^2 in MATLAB over the interval [0, 4π]. Participants are seeking assistance with MATLAB syntax and function plotting.

Discussion Character

  • Homework-related
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant expresses difficulty in writing the MATLAB code correctly, specifically regarding the placement of dots and brackets in the function.
  • Another participant points out that the initial definition of x is incorrect and suggests the correct syntax: x = [0:pi/4:4*pi].
  • There is confusion regarding the use of uppercase 'X' instead of lowercase 'x', which leads to incorrect results.
  • A suggestion is made to plot more points to improve the graph's accuracy, with an example provided: x=[1:100]/100 * 4 * pi; y = (sin(x) ./ x) .^2.
  • One participant insists on maintaining the specific form of the function as sin(x)^2/x^2, indicating a preference for clarity in the mathematical expression.
  • Another participant misinterprets the function and suggests sin(x^2)/x^2 instead, demonstrating a lack of familiarity with MATLAB.

Areas of Agreement / Disagreement

Participants generally agree on the need for correct syntax in MATLAB, but there is disagreement on the interpretation of the function and how it should be expressed in code.

Contextual Notes

Some participants express uncertainty about MATLAB syntax, particularly regarding the use of operators and function notation. There is also a lack of consensus on the correct form of the function to be plotted.

sara_87
Messages
748
Reaction score
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
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.
 
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 :)
 
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)
 
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... ;)
 
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!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K