You are on page 1of 3

Artificial Intelligence CS-331 Assignment # 1

Due Date: April 23, 2012 11:59 AM

Instructor

M. Zahid Iqbal
zahid.iqbal@uog.edu.pk Room# 211

Q#1: What will be the output of the following code. S = 1; n = 1; while S+(n+1)^2 < 100 n = n+1; S = S + n^2; end [n,S] Q#2: The area, A, of a triangle with sides of length a, b and c is given by A s(s a)(s b)(s c)) where s (a b c) / 2 . Write a MATLAB function that will accept the values a, b and c as inputs and return the value of A as output. a) You have to take input from the user for a,b and c. b) The first line of the file must have the format: function [list of outputs] = function name(list of inputs) c) Document the function. That is, describe briefly the purpose of the function and how it can be used. These lines should be preceded by % which signify that they are comment lines that will be ignored when the function is evaluated. d) What changes are required, if we want to return the value of s too from this function. Q#3: This is the Fibonnaci sequence defined by f1 0, f2 1 and fn fn1 fn2 , n 3, 4,5,...... construct a function that will return the nth number in the Fibonnaci sequence fn . Input: Integer n Output: fn

Q#4: We can generate a set of data with a random values about some mean value with the command num=100; spr=0.1; data=5.0+spr*sign(1.0-2.0*rand(1,num)).*rand(1,num) a) What is the last line doing? b) Write a program which computes the mean and standard deviation of the data. Use FOR LOOPs. Q#5: Write a function that takes a matrix as argument and then ask from the user that which operation you want to perform i.e. (+, -, *) then show the result. For example, if user asks to perform addition then program should show sum of all the values of that matrix. MATRIX CAN BE OF ANY DIMENSION. Q#6: Plot the following functions: (a) y = 3x+2 with x = 0, 0.25, 0.5, ...., 7.75, 8 (b) y = exp(-x^2) with x = 0, 0.1, 0.2, ..., 2 (c) y = ln(exp(x^-1)) with x = 1, 1.5, 2, ..., 4 NOTE: You have to submit a compressed file containing .m files for each question. You MUST have to mail me before deadline otherwise your assignment will be consider LATE or may not be accepted and you must have to submit this in hard form and in proper format before 23 Apr 2012 , 2:00 PM in my office. There can be demo of this assignment or quiz and your marks will based on that. So, in case of plagirism, you will surely get 100% 0 marks. Subject of your mail and the file name MUST be in following format. AssignmentNO_StudentName_StduentRollNo

Best of Luck

You might also like