Matlab program to plot Straight line
y = mx and y = mx + c.
where m is slope (or gradient) and c is y intercept of straight line.
y = mx and y = mx + c.
where m is slope (or gradient) and c is y intercept of straight line.
Matlab code:
clc; % Clear all input and output
clear all; % Clear all variables
x=[1 4 13 -4 -1];
m=1;
c=0;
y=m*x+c;
subplot(1,2,1);
plot(x,y); % Graph 2-D data with linear scales for both axes
axis([-10 20 -10 20]);
title('y=m*x');
xlabel('x-->');
ylabel('y-->');
grid;
c=5;
y1=-m*x+c;
subplot(1,2,2);
plot(x,y1);
axis([-10 20 -10 20]);
title('y=-m*x+c');
xlabel('x-->');
ylabel('y-->');
grid;
No comments:
Post a Comment