Basic arithmetic operations | Scigyan

Basic arithmetic operations

Basic-arithmetic-operations-logo
Matlab program for basic arithmetic operations - Addition, Subtraction, Multiplication and Division using simple matlab command.

Matlab code:

clc;            % Clear all input and output    
clear all;    % Clear all variables and objects in the matlab work-space
close all;    % Close all figures.
a=[1 2 3 4 5];    % 1st input
b=[1 1 1 1 1];    % 2nd input
c=a+b;               % Element by Addition
d=a-b;                % Element by Subtraction
e=a./b;               % Element by Division
f=a.*b;               % Element by Multiplication
subplot(3,3,1);   % Divides the current figure into rectangular panes
stem(a);              % Stem plots discrete sequence data
title('1st input');
xlabel('Index->');
ylabel('Magnitude');
subplot(3,3,2);
stem(b);
title('2nd input');        % Insert Title in the figure window
xlabel('Index->');      % Labels the x-axis
ylabel('Magnitude');  % Labels the y-axis
subplot(3,3,3);
stem(c);
title('Addition');xlabel('Index->');ylabel('Magnitude');
subplot(3,3,4);
stem(d);
title('Subtraction');xlabel('Index->');ylabel('Magnitude');
subplot(3,3,5);
stem(e);
title('Division');xlabel('Index->');ylabel('Magnitude');
subplot(3,3,6);
stem(f);
title('Multiplication');xlabel('Index->');ylabel('Magnitude');

Figure window

Basic-arithmetic-operations
No comments:
Post a Comment

Related Posts Plugin for WordPress, Blogger...