0% found this document useful (0 votes)
17 views2 pages

MATLAB Assignment II

This document is an assignment for a Computer Programming course at Addis Ababa University, focusing on MATLAB programming tasks. It includes short answer questions related to MATLAB scripts and requires students to write specific MATLAB functions for mathematical calculations and plotting. The assignment aims to assess students' understanding and application of programming concepts in MATLAB.

Uploaded by

sajinjunior1
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)
17 views2 pages

MATLAB Assignment II

This document is an assignment for a Computer Programming course at Addis Ababa University, focusing on MATLAB programming tasks. It includes short answer questions related to MATLAB scripts and requires students to write specific MATLAB functions for mathematical calculations and plotting. The assignment aims to assess students' understanding and application of programming concepts in MATLAB.

Uploaded by

sajinjunior1
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/ 2

ADDIS ABABA UNIVERSITY

ADDIS ABABA INSTITUTE OF TECHNOLOGY


SCHOOL OF CIVIL AND ENVIRONMENTAL ENGINEERING
CEng-2081: Computer Programming
Assignment 2

PART I: Short Answer

1. After executing the following script file in MATLAB


x = [2:4; ‐1:1; 1 2 3]; y = [1 2 4; 5 3 9; -4 2 3];
z=x'.*y the displayed result is

2. Consider the following MATLAB program:

S = (2 < 3) & ((2 > 8) |~ (1 +7>15))


What is the result of S? __________________

3. Consider the following MATLAB program:

A = ones( 4,4 ) + 2 * eye( 4,4 );


A=A-4
What is the value of A after this program executes?
4. Executing in the Command Window the following code, what is the result after this
program executes?
A = [2:4; ‐5 9 10; 4 6 3];
A(2,2)=15

PART II: Write a MATLAB code:

1. Write a MATLAB code for the following function:

Z= 2 e x  sin x 2  cos x 
2. x = linspace( -1,1,101 );y1 = exp(x );y2 = tan(x); y3=sin(x);

Write a MATLAB code to plot the three data sets in one plot and use color (blue, black and
red) to distinguish the data sets.

Computer Programming Page 1


3. Write a function to calculate the volume of a sphere of radius r. The volume of the sphere
4 3
with radius r is given by r .
3
4. Write a function that calculates the price of an item. If the value of the variable item is less
than 3, then the price can be computed by multiplying items by 150. In the second case, if
the value of the variable items is less than 5, then the price can be computed by multiplying
items by 140. If the value of the variable items is larger than 5, then the price can be
computed by multiplying the items by 130.

Abrham G. (P.hD)

Computer Programming Page 2

You might also like