Question

In: Computer Science

4) a.What are the rules in MATLAB for variable names and how do they compare to...

4)

a.What are the rules in MATLAB for variable names and how do they compare to the rules in C++.

b.Find a complete list of reserved symbols in MATLAB™. How does this list differ from the reserved symbols in C++.

c.What does “vectorization” mean. Explain very briefly why vectorisation is useful in MATLAB.

d.MATLAB contains a very versatile plot() function. What arguments are required to execute this function. Name two arguments that are optional. How many different line colours and marker shapes are available to this function ?

e.Write the first line of a MATLAB function (i.e. only the line starting with “function” that accepts a single variable and returns three different variables.

.

Solutions

Expert Solution

4.

(a) Rules for naming variables.

1.A valid variable name starts with a letter, followed by letters, digits, or underscores

2. MATLAB is case sensitive, so A and a are not the same variable.

3.The maximum length of a variable name is the value that the namelengthmax command returns.

4.You cannot define variables with the same names as MATLAB keywords, such as if or end.

Example for naming :

Valid vaeiable names Invalid variable names
x7 7x
lastValue end
n_factorial n!

(b)

  This table contains a comprehensive listing of all MATLAB operators, symbols, and special characters.

In MATLAB Name IN C++
+ addition +
+ unary plus ++
- subtraction -
- unary minus --
.* element multiplication *
* matrix multiplication *
/ matrix right division /
.^ power ^
.' transpose
== equal to ==
~= not equal to !=

&

logical AND &&
| Logical OR ||
&& AND with circuiting
|| OR with circuiting
@ at @
... ellipse ...
, comma ,
: colon :

(c)

  MATLAB is optimized for operations involving matrices and vectors. The process of revising loop-based, scalar-oriented code to use MATLAB matrix and vector operations is called vectorization. Vectorizing your code is worthwhile for several reasons:

  

  • Appearance: Vectorized mathematical code appears more like the mathematical expressions found in textbooks, making the code easier to understand.

  • Less Error Prone: Without loops, vectorized code is often shorter. Fewer lines of code mean fewer opportunities to introduce programming errors.

  • Performance: Vectorized code often runs much faster than the corresponding code containing loops.

(d)

The plot function in Matlab is used to create a graphical representation of some data. It is often very easy to "see" a trend in data when plotted, and very difficult when just looking at the raw numbers.

  1. Define x, by specifying the range of values for the variable x, for which the function is to be plotted.
  2. Define the function, y = f(x)
  3. Call the plot command, as plot(x, y)

The default colors used in MATLAB changed in R2014b version.There are now 14 colours as per the standare RGB triplets.

(e)

The basic representation of a function in matlab is :

function [a b c] = something(a, b, c) % 3 inputs, 3 outputs

function something(a,b) % 2 inputs, 0 outputs

In the above code a, b, c are the variables or the inputs.The first line of every function is the definition statement, which includes the following elements. Use lowercase characters for the keyword. If your function returns one output, you can specify the output name after the function keyword.


Related Solutions

assume that the data are stored in variable names x and y. write a matlab code...
assume that the data are stored in variable names x and y. write a matlab code to plot the quadratic spline and along with the data points x= 1 2 3 4 5 6 y= 40 78 125 256 348 425
How do technical analysis and quantitative decision rules compare to the process of following the various...
How do technical analysis and quantitative decision rules compare to the process of following the various stages of the economic cycle and macroeconomic indicators like unemployment, interest rates, economic growth, etc. At a very high level, provide examples of how a manager would use each “style” to guide investment decisions.
How do quantum number rules dictate periodicity?  
How do quantum number rules dictate periodicity?  
What are some of the names for rules have been implemented in situations where taxpayer in...
What are some of the names for rules have been implemented in situations where taxpayer in one country has a deduction but the recipient does not have taxable income where its received? List 3 examples - can be inbound or outbound.
Select two product names and then evaluate each with respect to the six rules for naming...
Select two product names and then evaluate each with respect to the six rules for naming a product.
How to design FIR lowpass filter using matlab. Note : Do not write matlab code. Only...
How to design FIR lowpass filter using matlab. Note : Do not write matlab code. Only explain the steps of designing filter
how do you demonstrate convultional and clock interleaving matlab?
how do you demonstrate convultional and clock interleaving matlab?
Compare and contrast the rules of the AICPA against the rules used in international audits under...
Compare and contrast the rules of the AICPA against the rules used in international audits under the International Ethics Standards Board for Accountants (IESBA)
Name three investment rules. Detail the mechanics for each of these rules and compare their advantages...
Name three investment rules. Detail the mechanics for each of these rules and compare their advantages and disadvantages. Finally, tell us which rule you personally prefer and why.
What are the other names that omitted variable bias is called?
What are the other names that omitted variable bias is called?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT