Homework 2

advertisement
Homework 2
CS-101-016
Due date:- 03/13/2013
Full Marks:-100
Problem 1:- Write a Matlab program, that takes a year as an input and determine whether the year
is a Leap year or not. (20)
Problem 2:- Write a Matlab program that determines the cost of sending a package. It takes the
weight of the package as input. If the package weight is within 15 pounds, the cost is 10$. If the
package weight is more than 15 but within 50 pounds, 2$ is added for each extra pound above 15
pounds. If the package weight is above 50 but within 100 pounds, 4$ is added for each extra pound
above 50. If the package weight is above 100, displays that the package cannot be send. (20)
Problem 3:- Write a Matlab program to create a calculator using switch construct. The program
will take two numbers as input, and will also take another number which indicate the choice of the
user whether user wants to add, subtract, multiply or divide. Hence the switch construct will have 4
cases, if case 1, the two numbers will be added, if case 2 the two numbers will be subtracted, if case
3 the two numbers will be multiplied and if case 4 the two numbers will be divided. (20)
Problem 4:- Write a program in Matlab to add two numbers from two arrays using try catch
construct. Initialize two arrays of different size, then prompt the user to input indexes for each of
the two array. Add the number from the arrays corresponding to the indexes and show the result
in the try block, if the index exceeds the length of the array, catch block will be executed. Within
the catch block display that the addition cannot be performed due to index out of bound error.
(20)
Problem 5:- Write Matlab code to solve the following system of simultaneous equations for x:
(10)
-2.0 x1 + 5.0 x2 + 1.0 x3 + 3.0 x4 + 4.0 x5 - 1.0 x6 = 0.0
2.0 x1 - 1.0 x2 - 5.0 x3 - 2.0 x4 + 6.0 x5 + 4.0 x6 = 1.0
-1.0 x1 + 6.0 x2 - 4.0 x3 - 5.0 x4 + 3.0 x5 - 1.0 x6 = -6.0
4.0 x1 + 3.0 x2 - 6.0 x3 - 5.0 x4 - 2.0 x5 - 2.0 x6 = 10.0
-3.0 x1 + 6.0 x2 + 4.0 x3 + 2.0 x4 - 6.0 x5 + 4.0 x6 = -6.0
2.0 x1 + 4.0 x2 + 4.0 x3 + 4.0 x4 + 5.0 x5 - 4.0 x6 = -2.0
Problem 6:-Write a Matlab program to determine the grade of a student. Input the marks obtained
by the student. If the marks is between 90-100 grade him A and display, if the marks is between
75-89, grade him B and display, if the marks is between 50-74 grade him C and display, if the
marks is between 35-49 grade him D and display, below that grade him F and display.(10)
Download