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, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- Construct a frequency distribution for the given data set using 6 classes. In the table, include the midpoints, relative frequencies, and cumulative frequencies. Which class has the greatest frequency and which has the least frequency? Question Viewer Amount (in dollars) spent on books for a semester 422 106 355 400 381 411 106 50 62 511 394 54 381 505 437 359 267 311 268 115 407 413 192 252 80 454 107 330 486 Complete the table, starting with the lowest class limit. Use the minimum data entry as the lower limit of the first class. (Type integers or decimals. Round the class limits to the nearest whole number. Round all other values to the nearest thousandth as needed.) Class 50-126 Frequency 9 Midpoint 88 Relative Frequency Cumulative Frequency 0.333 9arrow_forwardTo assure 99% confidence another poll is conducted, again asking whether or nothuman cloning should be allowed. 5,000 randomly selected adults from across thenation are surveyed. Of those surveyed 4,388 respond that they are against humancloning. Construct a 99% confidence interval estimate for the proportion of adults whoare against human cloning. Does this interval support the newspaper’s claim?arrow_forwardCould you help me please. Thank you!arrow_forward
- Can you help me with it please.arrow_forwardIn a recent national poll consisting of 1012 randomly selected adults. Participants wereasked whether or not human cloning should be allowed. Of those surveyed 900indicated human cloning should not be allowed. A newspaper releases and articleclaiming 90% of those across the nation are against human cloning based on thenational poll. Construct a 95% confidence interval estimate for the proportion of adultswho are against human cloning. Does this interval support the newspaper’s claim? What sample size would be needed to assure 99% confidence with an error bound of 0.02?arrow_forwardIn a recent national poll consisting of 1012 randomly selected adults. Participants wereasked whether or not human cloning should be allowed. Of those surveyed 900indicated human cloning should not be allowed. A newspaper releases and articleclaiming 90% of those across the nation are against human cloning based on thenational poll. Construct a 95% confidence interval estimate for the proportion of adultswho are against human cloning. Does this interval support the newspaper’s claim?arrow_forward
- It is known that 30% of all households still have landlines. If we randomly select 10 households, let X = number that have landlines a) FInd the probability that X = 3. b) Find the mean and standard deviation of X.arrow_forwardplease answer and show workarrow_forwardPlease answer and show workarrow_forward
- please answer and show workarrow_forwardSuppose you want to have $300,000 for retirement in 25 years. Your account earns 8% interest. a) How much would you need to deposit in the account each month? SA $ b) How much interest will you earn? $1 Message instructor Enter an integer or decimal number [more..] Question Help: Video Submit Question esc ! 1 F1 F2 80 F3 # $ 2 3 4 Ơ ☑ F4 F5 % <6 olo 50 F6 A F7 Q W E R T Y ab A lock Z S X D C 7 LL F G Harrow_forwardplease answer and show workarrow_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