251 Math Midterm PDF
251 Math Midterm PDF
Answers
1. A=[ 3 4 5 6 7 ; 13 14 15 16 17]
2. A=[ [3:7] ; [13:17] ]
Pookie =
4 6
2 3
1
V=[ A(:,1) ' A(:,2) ' A(:,3) ' ] '
W=[A(1,:) A(:,3)']
2
B='MY NAME IS JOHN SMITH'
B(12:15)='BILL'
>> A1=zeros(2,3);
>> A2=ones(2);
>> A3=eye(5);
>> A=[A1 A2;A3];
3
Solutions Mid 2-
Question 1: 4
Give the steps to solve the following system of linear equations using MATLAB.
2x-3y+4z=5
y+4z+x=10
-2z+3x+4y=0
Question 2: 6
(A)
>> x=[-5:0.1:5];y=[-5:0.1:5];
>> [A,B]=meshgrid(x,y);
>> Z=-(A/5).^2-(B/2).^2-16;
>> surf(A,B,Z)
>> colormap gray
>> xlabel('X-Axis'); ylabel('Y-Axis');
>> title('Question-2 of Midterm 2')
>> grid off
- (B)Give MATLAB commands to plot, on the same figure, the two functions:
function Z=Question3(x,y)
Z=exp(x).*cos(y)+sin(x.^2-y);
>> Question3(-3,4)
>> Question3(-5,-7)
>> x=-pi:0.1:pi;
>> y=-pi:0.1:pi;
>> z=Question3(x,y);
>> plot3(x,y,z)
(B) Write a M-File to calculate the square root of each element of the vector
v=16,10,34. Display the results in the form: “The square root is v” with a total of 6
digits with 2 digits after the decimal point.
v=[16 10 34];
r=sqrt(v);
fprintf('The square root is %f6.2\n',r);
Page 2 of 4
EXAM : MIDTERM I
ND
YEAR: 1433-1434H (SEM 2 ) المملكة العربية السعودية
COURSE NUMBER: MATH 251 وزارة التعليم العالي
DATE:01/05/1433H جامعة اإلمام محمد بن سعود اإلسالمية
DURATION: 1 HOUR كلية العلوم
INSTRUCTOR: Dr. Mohammed Messaoudi
Instructions:
For examiner
Question Mark Out of
Question 1 4.5
Question 2 4.5
Question 3 8
Question 4 3
Total 20
Page 1 of 5
4.5
Question 1:
I. Choose the correct answer (1)
1. Suppose x is a new variable, with the following MATLAB command,
>> x = [-10:-1:-15; -2:3];
What the is the size of x?
x=
-10 -11 -12 -13 -14 -15
-2 -1 0 1 2 3
IV. What is the difference between clc and clear commands? (1)
Page 2 of 5
Question 2: 4.5
I. Are the following variable assignment is correct? If no, explain why?
(1.5)
Two_2 (correct) √
example1_1 √
cos_2 √
which √
M251 √
II. Find the mistake in the following commands and correct them. (3)
>>P[ 1, 2] = 4 P(1, 2) = 4
Page 3 of 5
8
Question 3:
I .Let [ ] [ ] [ ] [ ]
[ ]
(5)
A=4*ones(6,6);
A(:,3:4)=3;
A(3:4,:)=3;
Question 4:
3
I. Ali went to the market. He bought 5kg of carrots (4SR/kg), 2kg of apples (7SR/kg), 6
lettuces (2 for 4SR) and 6 Pepsi (2SR each). What is the total amount?
Page 4 of 5
II. Write the MATLAB command for the following line
Page 5 of 5