0% found this document useful (0 votes)
77 views3 pages

MATLAB Programming Exercises for Engineers

This document is an exercise sheet for an Introduction to Computer Programming course. It contains 4 questions asking the student to use MATLAB commands to: 1) Store string values in variables and display them, 2) Calculate equivalent resistances in series and parallel circuits, 3) Find the roots of quadratic equations, and 4) Generate random numbers and calculate their statistics using built-in functions.

Uploaded by

Jk Jk
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)
77 views3 pages

MATLAB Programming Exercises for Engineers

This document is an exercise sheet for an Introduction to Computer Programming course. It contains 4 questions asking the student to use MATLAB commands to: 1) Store string values in variables and display them, 2) Calculate equivalent resistances in series and parallel circuits, 3) Find the roots of quadratic equations, and 4) Generate random numbers and calculate their statistics using built-in functions.

Uploaded by

Jk Jk
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

Introduction to Taif University

Computer Programming Faculty of Engineering


803213-3 Electrical Engineering Dept.
Exercise Sheet #3 Fall 2017

1. Write the MATLAB commands to perform the task specified below:


a. Store the string value 'I am studying' into variable named x and
store the string value 'Introduction to Computer Programming'
into variable y . During variable assignment, let MATLAB
display the value of x , but not the value of y
x = 'I am studying'
y = 'Introduction to Computer Programming';
b. Display the value of the pair composed of x and y , i.e., [ x y ]
[x y]

2. Follow the steps below to calculate the equivalent resistance of the


two resistors R1=6 Ω and R2=3 Ω in case the two resistors are connected
in series and in case they are connected in parallel:
a. Store the values of resistances R1 and R2 in two variables.
R1=6; R2=3;
b. Calculate the equivalent resistance in the series case using the
rule R s=R1 + R2
Rs = R1 + R2
c. Calculate the equivalent resistance in the parallel case using the

R R
1 2
rule R p = R + R
1 2

Rp = R1 * R2 / (R1 + R2)

3. Use MATLAB to find the roots of a quadratic equation in the general


form a x 2+ bx+ c=0 given the values fora , b andc . Namely, find the roots

−b ± √ b2−4 ac
x= , in each of the following cases:
2a
(i) a=1 ; b=3 ; c =2;

a=1; b=3; c=2;


1
x1=(-b-sqrt(b^2-4*a*c))/2/a
x2=(-b+sqrt(b^2-4*a*c))/2/a
(ii) a=1 ; b=2 ; c=2 ;

b = 2;
<<up arrow>> <<up arrow>> <<up arrow>> <<enter>>
<<up arrow>> <<up arrow>> <<up arrow>> <<enter>>
(iii) a=1 ; b=2 ; c=1 ;

c = 1;
<<up arrow>> <<up arrow>> <<up arrow>> <<enter>>
<<up arrow>> <<up arrow>> <<up arrow>> <<enter>>

4. Use MATLAB help to find the suitable built-in function to perform


the following task: Create a random vector x with 100 uniformly
distributed random numbers between 0 and 100. Find the minimum
value, the maximum value, the mean and the standard deviation of the
components of x .
help
look for “random”
help randfun
look for “uniformly distributed random numbers”
help rand

help
look for “data analysis”
help datafun
look for “minimum, maximum, mean, standard deviation”
help min
help max
help mean
help std

2
OR
doc
search for “uniformly distributed random numbers”,
“minimum”, “maximum”, “mean”, “standard devation”
read “rand”, “min”, “max”, “mean”, “std” built-in function
documentation
Script:
x = 100 * rand(1, 100)
min(x)
max(x)
mean(x)
std(x)

You might also like