You are on page 1of 5

UNIVERSITY OF JORDAN

SCHOOL OF ENGINEERING
DEPARTMENT OF MECHATRONICS ENGINEERING
Prepared by: Eng. Rasha Noufal
Computer Programming for Engineers/ MATLAB

Practice/assignment. 1

Focus of this week: General introduction to MATALB. The goal of this session is to become
familiar with MATLAB screen and perform simple tasks using MATLAB, such as generating an
arrays and matrices, define variables, and finding roots of a function, making a simple plot.
The commands to be entered in MATLAB screen are bolded

Proplem.1: Scalar variables: In command screen, assign the following variables

>> a=5*2
>> a=5*2; ( Notice the difference between this line and the previous line)
>> a=7+8/2
>> a=(7+8)/2
>> a=4+5/3+2
>> a=5^3/2
>> a=27^(1/3)+32^0.2
>>x=2;
>>y=2;
>>R=(y+5)*x
>>clc
>>R
>>clear R (clears the variable R from MATLAB)
>>R
>>pi
>>5/0
>>0/0
>> a=0.7854-(0.7854)^3/(1*2*3)+0.785^5/(1*2*3*4*5)…
-(0.785)^7/(1*2*3*4*5*6*7)

 
Problem 2 : complete the table below

Command Description Command Description Command Description


Example  Example Example 
290/7 
format short     
 
290/7 
format long     
 
290/7 
format short e     
 
290/7 
format long e     
 
290/7 
format short g     
 
290/7 
format long g     
 
290/7 
format bank     
 
 

Problem 3 :  

1. Calculate:

2. Suppose that X=2 and y =5. Use MATLAB to compute the following  

 
Problem. 4: Vector variables and arrays : Make the following variables

>>A =[3.1 59 26]


>>size (A)
>>B=[3.1 ; 59 ; 26]
>>size (B)
What is the difference between A and B.
>> K=[1:2:8] (Generates an array ( named K) for all the numbers between 1 and 9
with increment = 2)
>>K(3) (returns the third element in array K).
>>clear all
>>clc

Problem. 5: Finding the roots of a function

Use MATLAB to find the roots of 13 x3 + 182x2 ‐184x + 2503 = 0. 

Problem. 6: Solution of Linear Algebraic Equations


Using MATLAB, find the solution of the following linear system of equations:
6x + 12y + 4z = 70
7x – 2y + 3z = 5
2x + 8y – 9z = 64
 

Problem 7: A cube has a side of 18 cm.


(a) Determine the radius of a sphere that has the same surface area as the
cube.
(b) Determine the radius of a sphere that has the same volume as the cube.

Problem. 8 Plot of Given Data


In this case given data is used to create vectors that are then used in the plot command. The
following table contains sales data of a company from 1988 to 1994.

 
.
Problem. 9 : plot the function 3.5 cos 6 2 4.

Problem. 10: Plotting a function and its derivatives Plot the function 3 26 10. and its
first and second derivatives, for 2 4 , all in the same plot
 

Problem. 11: Write scrip file to execute the following  

 
Problem. 12: A cylindrical silo with radius r has a spherical
cap roof with radius R. The height of
the cylindrical portion is H. Write a program
in a script file that determines the
height H for given values of r, R, and the
volume V. In addition, the program calculates
the surface area of the silo.
Use the program to calculate the height and
surface area of a silo with r = 30 ft, R = 45
ft, and a volume of 120,000 ft3. Assign values
for r, R, and V in the Command Window.

Note : The total volume of the silo is obtained by


adding the volume of the cylindrical part and the volume of the spherical cap. The
volume of the cylinder is given by

Vcyl = πr2H

and the volume of the spherical cap is given by:

Which h 1

The θ can be clculated from

Using the equations above, the height, H, of the cylindrical part can be expressed by

The surface area of the silo is obtained by adding the surface areas of the cylindrical part and the
spherical cap.

You might also like