Concept explainers
To find:
The output of the following sequence of statements and expressions, and verify them.
mat = [1:3; 44 9 2; 5:-1:3]
mat(3, 2)
mat(2,:)
size(mat)
mat(:, 4) = [8;11;33]
numel(mat)
v = mat(3,:)
v(v(2))
v(1) = []
reshape(mat, 2, 6)
Answer to Problem 2.2P
Solution:
The output of the following sequence of statements and expressions:
“mat = [1:3; 44 9 2; 5:-1:3]”, “mat(3, 2)” “mat(2,:)”, “size(mat)”, “mat(:, 4) = [8;11;33]”, “numel(mat)”, “v = mat(3,:)”, “v(v(2))”, “v(1) = []”, and “reshape(mat, 2, 6)” are “
Explanation of Solution
Consider the following statement,
mat = [1:3; 44 9 2; 5:-1:3]
The statement will generates the matrix with the elements of the row with 1, 2, 3; second row 44, 9, 2; and the third row with 5, 4, 3.
So, the output is “
Consider the following statement,
mat(3, 2)
This command generates the value that is placed at third row and second column of the matrix “mat”.
So, the output is “ans = 4”.
Consider the following statement,
mat(2,:)
This command generates the second row elements of the matrix “mat”.
So, the output is “ans = 44 9 2”.
Consider the following statement,
size(mat)
This command generates the order of matrix.
So, the output is “ans = 3 3”.
Consider the following statement,
mat(:, 4) = [8;11;33]
This command includes the fourth column to the matrix “mat”.
So, the output is “
Consider the following statement,
numel(mat)
This command generates the number of elements present in the matrix “mat”.
So, the output is “ans = 12”.
Consider the following statement,
v = mat(3,:)
This command generates the third row elements from the matrix “mat”.
So, the output is “5 4 3 33”.
Consider the following statement,
v(v(2))
Since,
So, the output is “ans = 33”.
Consider the following statement,
v(1) = []
This command generates the elements of “v” eliminating the first elements.
So, the output is “v = 4 3 33”.
And consider the following statement,
reshape(mat, 2, 6)
This command changes the order of the matrix from
So, the output is “
MATLAB Code:
clc
clear all
close all
mat = [1:3; 44 9 2; 5:-1:3]
% Define the instruction in which the statement will generates the matrix with the elements of the row with 1, 2, 3; second row 44, 9, 2; and the third row with 5, 4, 3.
mat(3, 2)
% Define the instruction in which the command generates the value that is placed at third row and second column of the matrix “mat”.
mat(2,:)
% Define the instruction in which the command generates the second row elements of the matrix “mat”.
size(mat)
% Define the instruction in which the command generates the order of matrix.
mat(:, 4) = [8;11;33]
% Define the instruction in which the command includes the fourth column to the matrix “mat”.
numel(mat)
% Define the instruction in which the command generates the number of elements present in the matrix “mat”.
v = mat(3,:)
% Define the instruction in which the command generates the third row elements from the matrix “mat”.
v(v(2))
% Define the instruction in which the command generates the value of the v(v(2)).
v(1) = []
% Define the instruction in which the command generates the elements of “v” eliminating the first elements.
reshape(mat, 2, 6)
% Define the instruction in which the command changes the order of the matrix from 3 into 3 to 2 into 6.
Save the MATLAB script with name, chapter2_54793_2_2P.m in the current folder. Execute the script by typing the script name at the command window to find the answer of the given following sequence of statements and expressions.
Result:
Therefore, the output of the following sequence of statements and expressions:
“mat = [1:3; 44 9 2; 5:-1:3]”, “mat(3, 2)” “mat(2,:)”, “size(mat)”, “mat(:, 4) = [8;11;33]”, “numel(mat)”, “v = mat(3,:)”, “v(v(2))”, “v(1) = []”, and “reshape(mat, 2, 6)” are “
Want to see more full solutions like this?
Chapter 2 Solutions
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- Let X be a random variable with support SX = {−3, 0.5, 3, −2.5, 3.5}. Part ofits probability mass function (PMF) is given bypX(−3) = 0.15, pX(−2.5) = 0.3, pX(3) = 0.2, pX(3.5) = 0.15.(a) Find pX(0.5).(b) Find the cumulative distribution function (CDF), FX(x), of X.1(c) Sketch the graph of FX(x).arrow_forwardA well-known company predominantly makes flat pack furniture for students. Variability with the automated machinery means the wood components are cut with a standard deviation in length of 0.45 mm. After they are cut the components are measured. If their length is more than 1.2 mm from the required length, the components are rejected. a) Calculate the percentage of components that get rejected. b) In a manufacturing run of 1000 units, how many are expected to be rejected? c) The company wishes to install more accurate equipment in order to reduce the rejection rate by one-half, using the same ±1.2mm rejection criterion. Calculate the maximum acceptable standard deviation of the new process.arrow_forward5. Let X and Y be independent random variables and let the superscripts denote symmetrization (recall Sect. 3.6). Show that (X + Y) X+ys.arrow_forward
- 8. Suppose that the moments of the random variable X are constant, that is, suppose that EX" =c for all n ≥ 1, for some constant c. Find the distribution of X.arrow_forward9. The concentration function of a random variable X is defined as Qx(h) = sup P(x ≤ X ≤x+h), h>0. Show that, if X and Y are independent random variables, then Qx+y (h) min{Qx(h). Qr (h)).arrow_forward10. Prove that, if (t)=1+0(12) as asf->> O is a characteristic function, then p = 1.arrow_forward
- 9. The concentration function of a random variable X is defined as Qx(h) sup P(x ≤x≤x+h), h>0. (b) Is it true that Qx(ah) =aQx (h)?arrow_forward3. Let X1, X2,..., X, be independent, Exp(1)-distributed random variables, and set V₁₁ = max Xk and W₁ = X₁+x+x+ Isk≤narrow_forward7. Consider the function (t)=(1+|t|)e, ER. (a) Prove that is a characteristic function. (b) Prove that the corresponding distribution is absolutely continuous. (c) Prove, departing from itself, that the distribution has finite mean and variance. (d) Prove, without computation, that the mean equals 0. (e) Compute the density.arrow_forward
- 1. Show, by using characteristic, or moment generating functions, that if fx(x) = ½ex, -∞0 < x < ∞, then XY₁ - Y2, where Y₁ and Y2 are independent, exponentially distributed random variables.arrow_forward1. Show, by using characteristic, or moment generating functions, that if 1 fx(x): x) = ½exarrow_forward1990) 02-02 50% mesob berceus +7 What's the probability of getting more than 1 head on 10 flips of a fair coin?arrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell