Plots:
It is also easy to create plots in MATLAB.
y = f(x), and then plot the set points (xi, yi). By default matlab draws a straight line connecting neighboring points, The basic method for plotting a function f(x) in matlab is to create an array of x values, calculate a second array while the points themselves are invisible.
x1 = [0:0.25:4*pi]; % creates an array from 0 to 4*pi with a spacing of 0.25
x2 = linspace(0,4*pi,1000); % creates an array from 0 to 4*pi with 1000 evenly spaced points
y1 = 5*sin(x1).*cos(x1).^2; % calculate y = f(x)
y2 = 5*sin(x2).*cos(x2).^2; % note the use of the element-by-element operations .* .^ ./
plot(x1,y1);
hold on;
plot(x2,y2,’color’,’g’,’LineStyle’,’--’),’LineWidth’,2);
hold off;
No comments:
Post a Comment