0% found this document useful (0 votes)
57 views

Assignment

This MATLAB assignment involves writing programs to: 1) Generate a right angle triangle pattern from user input. 2) Plot different signals on the same figure, including linearly spaced and continuous data. 3) Plot multiple circles by varying the radius in a for loop. 4) Explain the results of executing MATLAB commands on a sample data set. 5) Calculate and display the average marks of multiple students over several subjects, storing results in a grades matrix.

Uploaded by

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

Assignment

This MATLAB assignment involves writing programs to: 1) Generate a right angle triangle pattern from user input. 2) Plot different signals on the same figure, including linearly spaced and continuous data. 3) Plot multiple circles by varying the radius in a for loop. 4) Explain the results of executing MATLAB commands on a sample data set. 5) Calculate and display the average marks of multiple students over several subjects, storing results in a grades matrix.

Uploaded by

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

King Abdulaziz University,

Faculty of Engineering
Department of Electrical and Computer Engineering
EE 201- Structured Computer Programming
Assignment - 1
Date: 25/05/2023 Sections: B10 & B90 Last Date to Submit: 01/06/2023
Note: Submit the Assignment as hard copy at my office or during your
EE201 Lecture time

Q1. Write a MATLAB program to make such a pattern like right angle triangle
given below.
Sample execution:
Enter the Number of rows = 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Q2. Write a MATLAB program that plots the following signals in the same figure
as follows:

a) Given that y1 = x1 𝑎𝑛𝑑 y2 = x2, where x1 is a vector that has 5 linearly


spaced points in the range from 0 to 10 and x2 is another vector ranges from
0 to 10 with a step size of 0.01. Plot y1 versus x1 and y2 versus x2 in the
first sub-figure.
b) Given a sine function f = sin(10t), where t is a vector ranges from 0 to 2π
with a step size of 0.01. Plot f versus t in the second sub-figure and control
axis scaling to be from -1 to 1 vertically and from 0 to 2π horizontally.
c) Add necessary data, use different colors, and add gridlines so that your
figure should look exactly as shown below:

y=x
10
Spaced Points
Continuous Data

5
y

0
0 1 2 3 4 5 6 7 8 9 10
x
f = sin(10t)
1
Sine Wave
0.5

0
f

-0.5

-1
0 1 2 3 4 5 6
t

(Or)
The following equation draws a circle with a center at the origin, where r is the
radius.
0<angle<2*pi
x=r*cos(angle)
y=r*sin(angle)
Then plot 10 circles using a for loop where the radius varies from 1 cm to
10 cm.
Circle with center at the origin
10

y -2

-4

-6

-8

-10
-10 -8 -6 -4 -2 0 2 4 6 8 10
x

When the radius is odd, plot the circles with blue solid line, when the radius is
even, plot it with red dashed line. Use switch case as conditional command.
Q3. Execute the following commands in MATLAB Command window and explain
the result of execution?
If x= [ 2 3 4 8 10 0 -2]
1) x(mod(x,2)= =0)=5*x(mod(x,2)= =0)

2) x(mod(x,2)= =0)=10

3) x(x>3)=5

4) z=x(x<=0)

5) x(mod(x,2)= =0 & mod(x,4)= =0)=100

Q4. Write the MATLAB program for the following sample execution.

Enter the number of students=3


Enter the number of subjects=3
enter the student ID=1111111
enter subject 1 marks of student ID 1111111 =100
enter subject 2 marks of student ID 1111111 =98
enter subject 3 marks of student ID 1111111 =96
the average of the student ID 1111111 is= 98
enter the student ID=2222222
enter subject 1 marks of student ID 2222222 =94
enter subject 2 marks of student ID 2222222 =96
enter subject 3 marks of student ID 2222222 =99
the average of the student ID 2222222 is= 96.3333
enter the student ID=3333333
enter subject 1 marks of student ID 3333333 =99
enter subject 2 marks of student ID 3333333 =97
enter subject 3 marks of student ID 3333333 =95
the average of the student ID 3333333 is= 97
Grades =
100 98 96
94 96 99
99 97 95
Hint: Store the first student’s Marks in 1st row of variable Grades.
Store the second student’s Marks in 2nd row of variable Grades and so on for
remaining students.

You might also like