0% found this document useful (0 votes)
10 views1 page

TPmatlab1 en

The document contains MATLAB exercises for a course at Lebanese University, focusing on various programming tasks such as executing MATLAB instructions, creating functions for factorial, sum and product, and determining the sign of a number. It includes specific MATLAB commands and functions to be implemented. Additionally, it provides a script that utilizes these functions to demonstrate their functionality.

Uploaded by

Houssien Alarab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

TPmatlab1 en

The document contains MATLAB exercises for a course at Lebanese University, focusing on various programming tasks such as executing MATLAB instructions, creating functions for factorial, sum and product, and determining the sign of a number. It includes specific MATLAB commands and functions to be implemented. Additionally, it provides a script that utilizes these functions to demonstrate their functionality.

Uploaded by

Houssien Alarab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Lebanese University M2207 2017-2018

Faculty of Sciences (I) MATLAB Sheet 1

Exercise 1 Give the result that we obtain by executing the following MATLAB instructions :
>> x = linspace(0,2,100) >> A = [1 2 3;4 5 6]
>> a = 10:-1:0 >> B = A.^2
>> b = -1:0.1:1 >> C = B’
>> y = x’ >> [m n] = size(A)
>> y = x.^2 >> M = [2 -1 0;3 1 1;0 5 2]
>> m = max(x) >> d = det(M)
>> L = length(x) >> U = inv(M)
>> plot(x,y,’r-*’,x,z,’g-s’); >> V = M*U

Exercise 2 Write a MATLAB function


function[y]=myFactorial(n)
which takes as input a positive integer n and returns the factorial of n, i.e.

y = n! = n ∗ (n − 1) ∗ (n − 2) ∗ · · · ∗ 1

Exercise 3 Write a MATLAB function


function[s, p]=mySumProd(v)
which takes as input a vector v and returns the sum s and the product p of the components of v,
X Y
s= vk , p= vk
k k

Exercise 4 Write a MATLAB function


function[s]=mySign(x)
which takes as input a real number x and returns 1 if x > 0, −1 if x < 0 and 0 if x = 0.

Exercise 5 Run the following MATLAB script that calls the above three MATLAB functions.

clear all;
clc;
y = myFactorial(5);
disp(y);
v = [1 3 -2 5 4 -3];
[s,p]=mySumProd(v)
for k=1:length(v)
s = mySign(v(k))
end

You might also like