Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
4th Edition
ISBN: 9780128045251
Author: Stormy Attaway Ph.D. Boston University
Publisher: Elsevier Science
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 2, Problem 2.1P
To determine

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)

Expert Solution & Answer
Check Mark

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 10n, here n=2,3,4.

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:

Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving, Chapter 2, Problem 2.1P , additional homework tip  1

Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving, Chapter 2, Problem 2.1P , additional homework tip  2

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Question 2: When John started his first job, his first end-of-year salary was $82,500. In the following years, he received salary raises as shown in the following table. Fill the Table: Fill the following table showing his end-of-year salary for each year. I have already provided the end-of-year salaries for the first three years. Calculate the end-of-year salaries for the remaining years using Excel. (If you Excel answer for the top 3 cells is not the same as the one in the following table, your formula / approach is incorrect) (2 points) Geometric Mean of Salary Raises: Calculate the geometric mean of the salary raises using the percentage figures provided in the second column named “% Raise”. (The geometric mean for this calculation should be nearly identical to the arithmetic mean. If your answer deviates significantly from the mean, it's likely incorrect. 2 points) Hint for the first part of question 2: To assist you with filling out the table in the first part of the question,…
Consider a sample with data values of 27, 25, 20, 15, 30, 34, 28, and 25. Compute the range, interquartile range, variance, and standard deviation (to a maximum of 2 decimals, if decimals are necessary). Range   Interquartile range   Variance   Standard deviation
Perform a Step by step  following tests in Microsoft Excel. Each of the following is 0.5 points, with a total of 6 points. Provide your answers in the following table. Median Standard Deviation Minimum Maximum Range 1st Quartile 2nd Quartile 3rd Quartile Skewness; provide a one sentence explanation of what does the skewness value indicates Kurtosis; provide a one sentence explanation of what does the kurtosis value indicates Make a labelled histogram; no point awarded if it is not labelled Make a labelled boxplot; no point awarded if it is not labelled   Data 27 30 22 25 24 22 20 28 20 26 21 23 24 20 28 30 20 28 29 30 21 26 29 25 26 25 20 30 26 28 25 21 22 27 27 24 26 22 29 28 30 22 22 22 30 21 21 30 26 20
Knowledge Booster
Background pattern image
Statistics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, statistics and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Text book image
College Algebra
Algebra
ISBN:9781305115545
Author:James Stewart, Lothar Redlin, Saleem Watson
Publisher:Cengage Learning
Text book image
Algebra: Structure And Method, Book 1
Algebra
ISBN:9780395977224
Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. Cole
Publisher:McDougal Littell
ALGEBRAIC EXPRESSIONS & EQUATIONS | GRADE 6; Author: SheenaDoria;https://www.youtube.com/watch?v=fUOdon3y1hU;License: Standard YouTube License, CC-BY
Algebraic Expression And Manipulation For O Level; Author: Maths Solution;https://www.youtube.com/watch?v=MhTyodgnzNM;License: Standard YouTube License, CC-BY
Algebra for Beginners | Basics of Algebra; Author: Geek's Lesson;https://www.youtube.com/watch?v=PVoTRu3p6ug;License: Standard YouTube License, CC-BY
Introduction to Algebra | Algebra for Beginners | Math | LetsTute; Author: Let'stute;https://www.youtube.com/watch?v=VqfeXMinM0U;License: Standard YouTube License, CC-BY