Sie sind auf Seite 1von 2

LAB No 1: EPE

Title: Introduction to basic programming in MATLAB.

Objectives: the purpose of this LAB is to get familiar with matrices, arrays,
graphics, data analysis and mathematics in MATLAB.
clc; % clear screen..
clear all; %%% clears all variables in work space.
TASK 1
%%%%%%%% WORKING WITH MATRICES.
A = [1 3 2 11; 5 12 15 8; 10 6 5 12; 14 16 1 19] %%% DEFINING A MATRIX;;
A_transpoase = A' %%%%%%% TRANSPOSE OF A MATRIX...
A_sum = sum(A)' %%%produces a column vector containing the row sums
A_diagonal=diag(A) %%%% gives the diagonalelements of a matrix.
sum_diagonal_elements = sum(A_diagonal) %%%%% TO PRODUCE THE SUM OF
DIAGONAL ELEMENTS.
sum_diagonal_elements = sum(diag(A)) %%%%%ALTERRNATIVE APPROACH TO PRODUCE
THE SUM OF DIAGONAL ELEMENTS
A(1,4) %%%% TO ACCES THE ELEMENT OF A MATRIX. A(i,j)
element_sum=A(1,4) + A(2,4) + A(3,4) + A(4,4) %%%%% SUM OF SELECTED
ELEMENTS.
B = [A A+32; A+48 A+16] %%%% CANCATENATION OF MATRICES
%%%You can delete rows and columns from a matrix using just a pair of square
brackets. Start with
X = A;
%%%Then, to delete the second column of X, use
X(:,2) = []

%%%%%%%% WORKING WITH ARRAYS.

%%%% AN ARRAY IS SUBSET OF MATRIX, WHERE EITHER ROW ARE ONE IN NUMBER OR
%%%% COLUMS ARE ONE IN NUMBER.
Y=[1 2 3 4 5 6]
Z=[1 ;2 ;3 ;4 ;5 ;6]
TASK 2
%%%%%%%% WORKING WITH PLOTS AND GRAPHICS..
figure(1) %%%% OPENS FIGURE(OPTIONAL)
x = 0:pi/100:2*pi; %%%%%% DEFINIG A ROW VECTOR WHICH CONTAINS ANGLES
y = sin(x);
plot(x,y)
grid on
xlabel('x = 0:2\pi')
ylabel('Sine of x')
title('Plot of the Sine Function','FontSize',12)

%%%%%%%% Plotting Multiple Data Sets in One Graph...


figure(2)
x = 0:pi/100:2*pi;
y = sin(x);
y2 = sin(x-.25); %%%%%% NOTE THE USE OF DOT OPERATOR HERE.
y3 = sin(x-.5);
plot(x,y,x,y2,x,y3)
Legend('sin(x)','sin(x-.25)','sin(x-.5)')
grid on
plot(x,y,'r') %%%%%%Specifying Line Styles and Colors
%%%%%%% see the matlab help for 'color_style_marker'
figure(3)
plot(x,y,'r') %%%%%%Specifying Line Styles and Colors
plot(x,y,'*')

%%%%%Placing Markers at Every Tenth Data Point


%%%%%You might want to use fewer data points to plot the markers than you use
to plot the lines...
%%%%%This example plots the data twice using a different number of points for
the dotted line and marker plots:
figure(4)
x1 = 0:pi/100:2*pi;
x2 = 0:pi/10:2*pi;
plot(x1,sin(x1),'r:',x2,sin(x2),'r+')
%%%%% Displaying Multiple Plots in One Figure
figure(5)
x1 = 0:pi/100:2*pi;
y1=sin(x1);
y2=sin(2.5*x1);
y3=sin(5*x1);
y4=sin(7.5*x1);
subplot(2,2,1)
plot(x1,y1);xlabel('radians');ylabel('Sine of x')
subplot(2,2,2)
plot(x1,y2);xlabel('radians');ylabel('Sine of 2.5*x')
subplot(2,2,3)
plot(x1,y3);xlabel('radians');ylabel('Sine of 5*x')
subplot(2,2,4)
plot(x1,y4);xlabel('radians');ylabel('Sine of 7.5*x')
%%%%%%%********************************************************************

TASK 3

y esin(5*t ) cos(6 * t ) sin(4* t )


Plot the function where t=0 to t=5 sec.
Properly label the figure in x and y axis and also add the suitable title.

Das könnte Ihnen auch gefallen