• Tidak ada hasil yang ditemukan

King Saud University College of Science

N/A
N/A
Protected

Academic year: 2025

Membagikan "King Saud University College of Science"

Copied!
3
0
0

Teks penuh

(1)

With best wishes Dr Mazin Zaindin

King Saud University College of Science

Department of Statistics & OR Second Semester 1433-1434

Second midterm examination - CSC 202 Question 1

Write a MATLAB script file that allows inputting a value for the variable x, and evaluates the following polynomial for that value:

1 − 𝑥 + 𝑥2 − 𝑥3 + ⋯ + 𝑥10 a) using a for-loop b) using a while-loop

Question 2

Rewrite the following script using if-else statement:

d = floor(10*rand);

switch d

case {2, 4, 6, 8}

disp( ’Even’ );

case {1, 3, 5, 7, 9}

disp( ’Odd’ );

otherwise disp( ’Zero’ );

end

Question 3

Draw a shape similar to the one depicted in Figure, by a Matlab command.

Question 4

Given the quadratic function: 𝑓(𝑥) = 𝑥2− 8𝑥 + 15,

1. Write a program to compute and display the values of x and f(x) over the range (0,8) with step 0.5.

2. Plot a graph of f(t), use a grid, write the text ‘Parabola example' as a title on top of the graph, label the x-axis as x, label the y-axis as f(x), and label the point (4,-1) as vertex

Question 5

Find the sum of the first 50 terms of the following series by vectorization:

ln(2) = 1 −1 2 +1

3− 1

4+ ⋯

(2)

With best wishes Dr Mazin Zaindin

Model Answer:

Q1) a)

x = input(‘Enter value for x: ’);

P = 0;

sign = 1;

for i = 0:10

P = P + sign * x.^i;

sign = - sign;

end disp(P);

b)

x = input(‘Enter value for x: ’);

P = 0;

sign = 1;

i=0;

while(i<=10)

P = P + sign * x.^i;

sign = - sign;

i = i +1;

end disp(P);

Q2)

d = floor(10*rand);

if (d==2)||(d==4) ||(d==6) ||(d==8) disp( ’Even’ );

elseif (d==1)||(d==3)||(d==5) ||(d==7)||(d==9) disp( ’Odd’ );

else

disp( ’Zero’ );

end Q3)

plot([0 1 0 2 4 3 4],[0 1 2 3 2 1 0]);

(3)

With best wishes Dr Mazin Zaindin

Q4)

x = 0:0.5:8;

f = x.^2 – 8*x + 15;

disp([x’ f’]);

plot(x,f), grid,

xlabel(‘x’), ylabel(‘f(x)’), title(‘Parabola example’), text(4,-1,’vertex’);

Q5)

x = 1:2:49;

y = 2:2:50;

S = sum(1./x) – sum(1./y);

disp(S);

Referensi

Dokumen terkait

Values meanings are: P1= 0 1 meansPkt1 destined to output upper lower link,P1=1 meansPkt1 is idle Buffer.Size number of currently buffered packets TotBuff total number of input

The fuzzy domain ontology is selected for our proposed approach because it possesses the details of a single domain only and more over it is used as concept map for the e-Learning

Age group classification using Correlation Frac- tal Dimension Step 1: Take facial image as Input Image Img Step 2: Crop the image Step 3: Convert the RGB image into Gray scale Image

of Contact Hrs Lecture + Tutorial/Lab 5 3+ 2+0 Level-Year 10-4 Prerequisite if any 211-EE-5 1 Course Objectives: To introduce students to the basic physics and operation of

of Contact Hrs Lecture + Tutorial/Lab 2 0+0+2 Level-Year 13 - 5 Prerequisite if any Co 512-EE-4 1 Course Objectives: The course is designed to complement Digital Signal

x fx Chapter 1:Lmits and Continuity 14 One-Sided Limits ● Definition: We write as the left-hand limit of fx as x approaches a [limit of fx as x approaches a from the left] is equal

Overview We will compute points between x=0 and x=y and then draw the 8 matching points In that area, the slope of the curve is between 0 and -1 From each step/point x, y, the next

1.5 Exercise 5 Write the static, recursive method mergeTwo which receives two arrays of sorted integers and returns a merged, sorted array containing the elements of both.. Your method