MATLAB Questions and Answers – Functions and Expressions

«
»

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Functions and Expressions”.

1. How many expressions are there in the following mathematical relation?

advertisement
 a=sqrt(log(sqrt(x+y)))

a) 2
b) 3
c) 1
d) 4
View Answer

Answer: b
Explanation: The given relation has 3 functions but it has 4 expressions in itself. sqrt(x+y) is an expression while sqrt() is the function. log(sqrt(x+y)) is a separate expression while log() is the function. sqrt(log(sqrt(x+y))) is entirely an expression. The entire mathematical relation is an expression used to describe that a is equal to sqrt(log(sqrt(x+y))); this is important since we are sure about the nature of the relationship between a,x and y. Hence, there are 4 expressions which successfully describe the mathematical relation between the variables a,x and y.
advertisement
advertisement

2. How many functions are there in the following mathematical relation?

	p=sin(pi*(log(x))

a) 2
b) 3
c) 1
d) 0
View Answer

Answer: a
Explanation: There are only 2 functions used to describe a meaningful relationship between p and x. They are the sin() and log(x). Now, the expression ‘pi*log(x)’ is not to be confused as a function since we have not created a function i.e. we have not made a self-containing block of statements with an algorithm to compute the value after multiplying pi with log(x). The ‘*’ operator is used directly to the expression does not serve as a function, it shows an operation. Hence there are only 2 functions.
advertisement

3. What are the minimum numbers of expressions which will be required to express a mathematical relation?
a) At least 1
b) At least 2
c) At most 1
d) Depends on the number of variables
View Answer

Answer: d
Explanation: If we have a very big expression relating a variable y with any no. of variables x1,x2…xn we can put the entire expression on the right hand side within a function and reduce the expression to
y=func(x1,x2,x3…xn)
This contains two expressions only. The function, ‘func’, may contain a set of 10000 statements. But we have simplified the expression to demonstrate a mathematical relation between y and all the other variables of the right-hand side, provided we are sure about the nature of the function ‘func’.

4. Is it possible to reduce the number of expressions in the following mathematical relation?

advertisement
a=sin(pi*log(x))

a) Yes
b) No
c) Maybe
d) Impossible
View Answer

Answer: a
Explanation: We can define a function, say func, which contains the block of statements, required, to compute the given relation and return the value. Then we can say
a=func(x)
We have 2 expressions now while the previous statement had 4 expressions. Hence, we have reduced the number of expressions.
advertisement

5. Is it possible to reduce the number of functions in the following mathematical relation?

	l=cos(2*pi*sin(n/x))

a) Yes
b) No
c) Maybe
d) Obviously
View Answer

Answer: b
Explanation: We cannot reduce the number of functions which are required to express a mathematical relation amongst variables. This is because those functions compute the value of the dependent variable for any value of the independent variable. In some cases, we may approximate the values of the dependent variable- but we are approximating the functional operation, we are not deleting the function.

6. The teacher has given the assignment to find the sum of 2 numbers. But the code should not contain the ‘+’ operator. What is to be done?
a) Use a function
b) Add the values and print the sum directly
c) Use an expression
d) Cannot be done
View Answer

Answer: a
Explanation: The power of a function is to hide the statements which are used to complete our task. So the student can create a function file to add two numbers. Hence, the code will not show the ‘+’ operator but it will be used implicitly.

7. How many expressions are used to describe a mathematical relation between a, b and c?

b=9; c=4;
a=b+c;

a) 4
b) 2
c) 3
d) 1
View Answer

Answer: b
Explanation: The code has 4 expressions, ‘b=9’, ‘c=4’, ‘b+c’, and ‘a=b+c’. The mathematical relation is described by ‘a=b+c’ only which contains 2 expressions. Hence, there are two expressions that has been used to describe a mathematical relation between a, b and c.

8. A mathematical statement is a combination of functions and variables only.
a) True
b) False
View Answer

Answer: b
Explanation: An expression is a combination of variables, operators and functions. It is not necessary that only functions and variables are present in a mathematical expression. The statement ‘a=b+c’ contains no functions, but it only performs the addition operation between b and c and assigns the value to a. The statement a=sum(b,c) shows no mathematical operation explicitly since the operation is done by the function itself.

9. What is the command which can be used to see the expressions within a user-defined function in MATLAB?
a) help
b) look for
c) echo on
d) cannot be seen
View Answer

Answer: c
Explanation: A user-defined function is a function file. The commands ‘help’ and ‘look for’ will only return the nature of in-built function. If the function file has ‘echo on’, it will display the expressions in the function file while executing. This is because function files, though they are different from script files, are inherently M-files.

10. What are mathematical expressions?
a) Any mathematical relation
b) Any mathematical operation
c) Any mathematical conversation
d) Any mathematical function
View Answer

Answer: b
Explanation: A mathematical function is used to relate a dependent variable with an independent variable so it is used to operate on the independent variable. Similarly, any mathematical relation is used to relate an independent variable with a dependent variable. This is also an operation since based on the value of the independent variable, we comment on the value of the dependent variable. Hence a mathematical expression is simply any mathematical operation.

Sanfoundry Global Education & Learning Series – MATLAB.

To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter