0% found this document useful (0 votes)
7 views5 pages

CSC 111 Assignment 1

This document is an assignment for a Computer Programming course (CSC111) at the College of Engineering, focusing on MATLAB commands, variable naming rules, and coding exercises. It includes exercises for knowledge review, basic practice, and coding MATLAB scripts, with specific tasks such as writing MATLAB expressions and codes for calculating potential energy, temperature conversion, and finding roots of a quadratic equation. The assignment is structured into multiple exercises with designated marks for each section.

Uploaded by

rakansasore
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)
7 views5 pages

CSC 111 Assignment 1

This document is an assignment for a Computer Programming course (CSC111) at the College of Engineering, focusing on MATLAB commands, variable naming rules, and coding exercises. It includes exercises for knowledge review, basic practice, and coding MATLAB scripts, with specific tasks such as writing MATLAB expressions and codes for calculating potential energy, temperature conversion, and finding roots of a quadratic equation. The assignment is structured into multiple exercises with designated marks for each section.

Uploaded by

rakansasore
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/ 5

College of Engineering

Electrical Engineering Department

Computer Programming
(CSC111)

Semester 462 (2025)

Assignment #1

Student’s Name: ID#

Date of Assignment: Group:

Page 1 of 5
Exercise 1: Knowledge Review (0.6 Marks)

1) Write a short answer for the use of each of the following MATLAB commands. (0.2)
a) clear
b) whos
c) doc

---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

2) Write four rules for naming variables in MATLAB. (0.2)

---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------
3) Explain the use of each of the following MATLAB functions with the help of an example.
Note: Please use the MATLAB Command Window to test each function before answering.
a) sqrt (0.2)
b) log
c) log10
d) exp
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Page 2 of 5
Exercise 2: Basic Practice Review (0.6 Marks)

1) Write MATLAB expressions for the following (0.3)


√ 3+ 𝑥 2
a) 𝑦 =
ln(𝑥+2)
b) y = cos(𝑥) |(𝑥 2 − 𝑥 + 1) | (Note: The vertical bars here represent the absolute value)
exp(𝑥 2 ) sin(𝑥)+2𝑥
c) 𝑦 = − log10 𝑥
ln (𝑥 2 +7)

Solution(a):
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Solution(b):
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Solution(c):
---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
2) Below are some variable names and their assigned values. Identify which variable names are incorrect
and explain why they are invalid according to MATLAB's variable naming rules: (0.3)
a) x y = 10
b) value_1 = 7
c) 4num = 20
d) a#b = 5

Solution:
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

Page 3 of 5
Exercise 3: Coding MATLAB Scripts (0.8 Marks)

1) Write a MATLAB code to calculate and display the potential energy(PE=mgh) of an object given
the following values: (0.3)

o Mass: m=5
o Height: h=10
o Gravitational acceleration: g=9.8

Solution:
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

2) Write a MATLAB code to calculate the temperature in Celsius for a given Fahrenheit value.
Given the following value: (0.3)

o Fahrenheit F=80
5(𝐹−32)
Use the formula: 𝐶 =
9
Solution:
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------

Page 4 of 5
3) Write a MATLAB code to find and display the roots of the quadratic equation 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 =
0, given the following values: (0.4)
o a=1
o b=−5
o c=6

Use the quadratic formula:


−𝑏+√𝑏2 −4𝑎𝑐 −𝑏−√𝑏2 −4𝑎𝑐
𝑥1 = & 𝑥2 =
2𝑎 2𝑎

Solution:

-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------

The End

Page 5 of 5

You might also like