
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
- Don’t solve questionsarrow_forwardFred needs to choose a password for a certain website. Assume that he will choose an 8-character password, and that the legal characters are the lowercase letters a, b, c, ..., z, the uppercase letters A, B, C, ..., Z, and the numbers 0, 1, . . ., 9. (a) How many possibilities are there if he is required to have at least one lowercase letter in his password? (b) How many possibilities are there if he is required to have at least one lowercase letter and at least one uppercase letter in his password? (c) How many possibilities are there if he is required to have at least one lowercase letter, at least one uppercase letter, and at least one number in his password?arrow_forwarda =1500, b=1700 what is percentage of a is barrow_forward
- A 12-inch bar that is clamped at both ends is to be subjected to an increasing amount of stress until it snaps. Let Y = the distance from the left end at which the break occurs. Suppose Y has the following pdf. f(y) = { (a) Compute the cdf of Y. F(y) = 0 0 y -옴) 0 ≤ y ≤ 12 1- 12 y 12 Graph the cdf of Y. F(y) 1.0 0.8 0.6 0.4 0.2 y 2 6 8 10 12 F(y) F(y) F(y) 1.01 1.0ㅏ 1.0 0.8 0.6 0.4 0.2 0.8 0.8 0.6 0.4 ཨཱུ སྦེ 0.6 0.4 0.2 2 4 6 8 10 12 (b) Compute P(Y ≤ 5), P(Y > 6), and P(5 ≤ y ≤ 6). (Round your answers to three decimal places.) P(Y ≤ 5) = P(Y > 6) = P(5 ≤ y ≤ 6) = (c) Compute E(Y), E(y²), and V(Y). E(Y) = in E(Y2) v(x) = in 2 2 2 4 6 8 10 12 y 2 4 6 8 10 12arrow_forwardA restaurant serves three fixed-price dinners costing $12, $15, and $20. For a randomly selected couple dining at this restaurant, let X = the cost of the man's dinner and Y = the cost of the woman's dinner. The joint pmf of X and Y is given in the following table. p(x, y) 15 y 12 20 12 0.05 0.10 0.35 x 15 0.00 0.20 0.10 20 0.05 0.05 0.10 (a) Compute the marginal pmf of X. x 12 Px(x) Compute the marginal pmf of Y. y Pyly) 12 15 20 15 20 (b) What is the probability that the man's and the woman's dinner cost at most $15 each? (c) Are X and Y independent? Justify your answer. X and Y are independent because P(x, y) = Px(x) · Py(y). X and Y are not independent because P(x, y) =Px(x) · Pyly). X and Y are not independent because P(x, y) * Px(x) · Py(y). X and Y are independent because P(x, y) * Px(x) · Py(y). (d) What is the expected total cost, in dollars, of the dinner for the two people? $ (e) Suppose that when a couple opens fortune cookies at the conclusion of the meal, they find the…arrow_forwardLet X = the time between two successive arrivals at the drive-up window of a local bank. If X has an exponential distribution with λ = 1, (which is identical to a standard gamma distribution with α = 1), compute the following. (If necessary, round your answer to three decimal places.) (a) the expected time between two successive arrivals (b) the standard deviation of the time between successive arrivals (c) P(X ≤ 1) (d) P(2 ≤ X ≤ 4) You may need to use the appropriate table in the Appendix of Tablesarrow_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

