
Concept explainers
To find:
The output of the following sequence of statements and expressions, and verify them.
pvec = 3:2:10
pvec(2) = 15
pvec(7) = 33
pvec([2:4 7])
linspace(5, 11, 3)
logspace(2, 4, 3)

Answer to Problem 2.1P
Solution:
The output of the following sequence of statements and expressions:
“pvec = 3:2:10”, “pvec(2) = 15” “pvec(7) = 33”, “pvec([2:4 7])”, “linspace(5, 11, 3)”, and “logspace(2, 4, 3)” are “pvec = 3 5 7 9”, “pvec = 3 15 7 9 0 0 33”, “ans = 15 7 9 33”, “ans = 5 8 11”, and “ans = 100 1000 10000” respectively.
Explanation of Solution
Consider the following statement,
pvec = 3:2:10
The statement will generate the sequence of number from 3 to 10 in increment of 2.
So, the output is “pvec = 3 5 7 9”.
Consider the following statement,
pvec(2) = 15
The expression replaces the second term of the sequence of “pvec” with “15” and then displays sequence.
So, the output is “pvec = 3 15 7 9”.
Consider the following statement,
pvec(7) = 33
The expression replaces the seventh term of the sequence of “pvec” with “33” and then displays sequence. Since, the values of the 5th and the 6th terms are not allotted, so these terms are allotted with zero.
So, the output is “pvec = 3 15 7 9 0 0 33”.
Consider the following statement,
pvec([2:4 7])
The expression displays the values placed 2nd to 4th and then 7th from the sequence.
So, the output is “ans = 15 7 9 33”.
Consider the following statement,
linspace(5, 11, 3)
The expression generates three values that are equally spaced from 5 to 11.
So, the output is “ans = 5 8 11”.
And, consider the following statement,
logspace(2, 4, 3)
The expression generates three values that are equal to
So, the output is “ans = 100 1000 10000”.
The
MATLAB Code:
clc
clear all
close all
pvec = 3:2:10
% Define the instruction to generate the sequence of number from 3 to 10 in increment of 2.
pvec(2) = 15
% Define the instruction in which the expression replaces the second term of the sequence of “pvec” with “15” and then displays sequence.
pvec(7) = 33
% Define the instruction in which the expression replaces the seventh term of the sequence of “pvec” with “33” and then displays sequence. Since, the values of the 5th and the 6th terms are not allotted, so these terms are allotted with zero.
pvec([2:4 7])
% Define the instruction in which the expression displays the values placed 2nd to 4th and then 7th from the sequence.
linspace(5, 11, 3)
% Define the instruction in which the expression generates three values that are equally spaced from 5 to 11.
logspace(2, 4, 3)
% Define the instruction in which the expression generates three values that are equal to 10^n, here n = 2, 3, 4.
Save the MATLAB script with name, chapter2_54793_2_1P.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:
“pvec = 3:2:10”, “pvec(2) = 15” “pvec(7) = 33”, “pvec([2:4 7])”, “linspace(5, 11, 3)”, and “logspace(2, 4, 3)” are “pvec = 3 5 7 9”, “pvec = 3 15 7 9 0 0 33”, “ans = 15 7 9 33”, “ans = 5 8 11”, and “ans = 100 1000 10000” respectively.
Want to see more full solutions like this?
Chapter 2 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Examine the Variables: Carefully review and note the names of all variables in the dataset. Examples of these variables include: Mileage (mpg) Number of Cylinders (cyl) Displacement (disp) Horsepower (hp) Research: Google to understand these variables. Statistical Analysis: Select mpg variable, and perform the following statistical tests. Once you are done with these tests using mpg variable, repeat the same with hp Mean Median First Quartile (Q1) Second Quartile (Q2) Third Quartile (Q3) Fourth Quartile (Q4) 10th Percentile 70th Percentile Skewness Kurtosis Document Your Results: In RStudio: Before running each statistical test, provide a heading in the format shown at the bottom. “# Mean of mileage – Your name’s command” In Microsoft Word: Once you've completed all tests, take a screenshot of your results in RStudio and paste it into a Microsoft Word document. Make sure that snapshots are very clear. You will need multiple snapshots. Also transfer these results to the…arrow_forward2 (VaR and ES) Suppose X1 are independent. Prove that ~ Unif[-0.5, 0.5] and X2 VaRa (X1X2) < VaRa(X1) + VaRa (X2). ~ Unif[-0.5, 0.5]arrow_forward8 (Correlation and Diversification) Assume we have two stocks, A and B, show that a particular combination of the two stocks produce a risk-free portfolio when the correlation between the return of A and B is -1.arrow_forward
- 9 (Portfolio allocation) Suppose R₁ and R2 are returns of 2 assets and with expected return and variance respectively r₁ and 72 and variance-covariance σ2, 0%½ and σ12. Find −∞ ≤ w ≤ ∞ such that the portfolio wR₁ + (1 - w) R₂ has the smallest risk.arrow_forward7 (Multivariate random variable) Suppose X, €1, €2, €3 are IID N(0, 1) and Y2 Y₁ = 0.2 0.8X + €1, Y₂ = 0.3 +0.7X+ €2, Y3 = 0.2 + 0.9X + €3. = (In models like this, X is called the common factors of Y₁, Y₂, Y3.) Y = (Y1, Y2, Y3). (a) Find E(Y) and cov(Y). (b) What can you observe from cov(Y). Writearrow_forward1 (VaR and ES) Suppose X ~ f(x) with 1+x, if 0> x > −1 f(x) = 1−x if 1 x > 0 Find VaRo.05 (X) and ES0.05 (X).arrow_forward
- Joy is making Christmas gifts. She has 6 1/12 feet of yarn and will need 4 1/4 to complete our project. How much yarn will she have left over compute this solution in two different ways arrow_forwardSolve for X. Explain each step. 2^2x • 2^-4=8arrow_forwardOne hundred people were surveyed, and one question pertained to their educational background. The results of this question and their genders are given in the following table. Female (F) Male (F′) Total College degree (D) 30 20 50 No college degree (D′) 30 20 50 Total 60 40 100 If a person is selected at random from those surveyed, find the probability of each of the following events.1. The person is female or has a college degree. Answer: equation editor Equation Editor 2. The person is male or does not have a college degree. Answer: equation editor Equation Editor 3. The person is female or does not have a college degree.arrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageCollege AlgebraAlgebraISBN:9781305115545Author:James Stewart, Lothar Redlin, Saleem WatsonPublisher:Cengage LearningAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell

