please give the Matlab code of the following question 1. Create a function that
ID: 3198876 • Letter: P
Question
please give the Matlab code of the following question
1. Create a function that takes matrix as a parameter. If the amount of rows in the given matrix is less tharn four, function should return 0, if the amount of rows is greater or equal to four, function should delete three last rows of a matrix and swap last column with the first column and return such a matrix. Create a matrix in MATLAB command window and check the functionality of a created function. What commands have you used to create a matrix and to call function? (5 points) 2. Create a scenarios file to implement a graph of given functions (argument should be from the interval show three graphs in different plots in 5, S], step size 0.l): /(x)-rsin x,)-sin x +1 the same graphical window. Add title to each plot. (5 points) 3. Save your work (two MATLAB m files and screenshot of MATLAB command window with used scenarios and comm ands from MATLAB command commands or a Word file with texts of function, window) and send created file to the teacher (sergeius.ivanikovas@vgtu.lb).Explanation / Answer
% Here is the function, receives a matrix as an input
function output = functionmatrix( matrix )
[m,n]=size(matrix);
if m<4
output=0;
else
%Delete last 3 rows
matrix = matrix(1:m-3,:);
%Swap first and las columns
matrix(:,[1 n])=matrix(:,[n 1]);
output=matrix;
end
end
% this is the Script for problem 2
x=-5:0.1:5;
f=x.*sin(x);
f1=(x-1)./(x+1);
f2=sin(x.^2)./(x.^2);
subplot(3,1,1);
plot(x,f)
title('Plot 1 x*sin(x)')
subplot(3,1,2);
plot(x,f1)
title('Plot 2 (x-1)/(x+1)')
subplot(3,1,3);
plot(x,f2)
title('Plot 3 sin(x^2)/x^2')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.