In the script, enter the commands to perform the following three calculations, using the equivalent MATLAB operators
No answer yet for this question.
Ask a Tutor
Question:
In the script, enter the commands to perform the following three calculations, using the equivalent MATLAB operators and functions:
- 5sqrt(5) - 60/5+9*3
- 4^3 - |-6| - 9pi
- cos^2(pi/3)-ln(1)+9e^-1
- Part 2.In the script, complete the following steps
- Write 3 different methods to define the following row vector: j = [-6 -3 0 3 6 9 12]
- Write an single expression to compute a vector k, such that each element of k is related to the corresponding element of j (from part 2A) via the relation below. k = 2j2-6j +13
- Part 3.In the script, define the variable "MB" as the number of the month you were born. The value inside this variable can be a number of your choice from 1 to 12. That is, initialize the variable MB with a chosen number from 1 to 12. For example if my birthday is in October, MB would equal 10 With this variable defined, write an if-elseif-else statement so that, when executed, If you are born in a Spring month (March, April, May) then the word 'spring' is displayed in the command window. If you are born in a Summer month (June, July, August) then the word 'summer' is displayed in the command window. If you are born in a Fall month (September, October, November) then the word 'fall' is displayed in the command window. If you are born in a Winter month (December, January, February) then the word 'winter' is displayed in the command window.
- Part 4.In the script, define a variable "n" whose value is (initialized to) a natural number of your choice (e.g., n = 100;). Write an for-loop to compute factorial of n, i.e., compute the product of first n natural numbers. (e.g., 5 factorial = 5! = 120) Do not use the pre-existing "prod" or "factorial" functions in MATLAB, you must use the for-loop along with simple operations like multiplication. At the end of the for-loop, write a statement to print the final output of n factorial in the command window.
- Part 5.At the end of the script, define a MATLAB function whose name is of your choice. The function must take as input (argument) a user specified vector of length 5 with five numbers in it, and produce as output (i.e. return) the sum of squares of those numbers. To show that your function works, in the script write an expression to call this function and print/display the sum of squares of 2, 4, 6, 8, and 10 in the command window. I.e., your when you give [2 4 6 8 10] as input to your function, it should produce the result 220. Note: Even though you are calling the function in part 5 here, the function has to be defined at the end of the script. That is how MATLAB likes its function definitions.
- Part 6.In the script, define appropriate vectors and plot the following two functionsin a single plot. Make sure to use different line attributes to differentiate the two curves, add a title to the plot, label the axes, and add a legend.
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: