In: Electrical Engineering
I am trying to plot a difficult function in MATLAB, however I need to understand the basics first.
I am trying to plot
n=0
for x=0:0.01:2pi
n=n+1
y(n)=sin(x)
end
I beleive what this says, is that I want to plot sin(x) over a full period hence from o to 2pi, and I beleive the 0.01 is the incremenation along the x-axis. I am not sure what my n is doing
Could smeone please graph this for me with the MATLAB code as well, and show was you were doing and what the functions and things mean for exaple what ":" means and so on
A simple program to plot y=sin(x) is shown below
The ":" is an operator in MATLAB. It is used to represent an increament in a MATLAB expression. In this particular question, x=0:0.01:(2*pi) represents that the value of 'x' for which the sine value is caluculated. The initial vale of x=0. It is then to be incremented after each calulation. The second value of x=0+0.01; third value would be x=0.01+0.01 and so on. This means that after every calculation the value of x is incremented by 0.01. This would continue until the value of x reaches to (2*pi) which is equal to approximately 6.28.