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
- Find the term of (x² +x-3)"0 that has x185 in it.arrow_forwardAnswers must be in 4 decimals A witness to a hit-and-run accident told the police that the license number of the car contained the letters DGR followed by 3 digits, the first of which is a 3. If the witness cannot recall the last 2 digits, but is certain that all three digits are different and nonzero, find the maximum number of car registrations that the police may have to check.arrow_forwardpts 1 pts S 1 pts 1 pts 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2reg Write each of the following numbers in exponential or scientific notation. Write each number to two decimal places with only one non-zero digit before the decimal point. Example: Use 1.20 × 10-4 not 0.120 x 10-³ or 12.0 x 10-5 0.00265 113 0.0000947 4850000 [Review Topics] [References] Use the References to access important values if needed for this question. Submit Answer Retry Entire Group 9 more group attempts remaining U 7 pts 7 pts M 1 pts M 1 pts 2req O 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2req 1 pts 2req 1pts 2req [Review Topics) References) Use the References to access important values if needed for this question Write each of the following numbers in exponential or scientific notation. Write each number to two decimal places with only one non-zero digit before the decimal point. Example: Use 1.20 x 10 0.120 x 10 12.0 x 10 not or 0.00265 113 0.0000947 4850000 Submit…arrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageCollege AlgebraAlgebraISBN:9781305115545Author:James Stewart, Lothar Redlin, Saleem WatsonPublisher:Cengage LearningElementary Geometry for College StudentsGeometryISBN:9781285195698Author:Daniel C. Alexander, Geralyn M. KoeberleinPublisher:Cengage Learning
- Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell