Thursday, 4 August 2016

MATLAB Programming 49 - adding some functionality to graph (2)


Drawing Multiple Functions on the Same Graph


You can draw multiple graphs on the same plot. The following example demonstrates the concept:

Example


Create a script file and type the following code:


Define x as 100 linearly spaced values between $-2\pi$ and $2\pi$. Define y1 and y2 as sine and cosine values of x. Create a line plot of both sets of data.

x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);

figure
plot(x,y1,x,y2)


No comments:

Post a Comment