Straight line plots | Scigyan

Straight line plots

Straight-line-plots-logoMatlab 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.

Matlab code:

clc;         % Clear all input and output 
clear all; % Clear all variables 
close all; % Close all figures.
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;

Figure window

Straight-line-plots
No comments:
Post a Comment

Related Posts Plugin for WordPress, Blogger...