csc 1240 ch 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

This function's argument units must be in radians

cos

This function's argument units must be in degrees

cosd

For the statement "fprintf("Apples\nPears\nOranges")", how many lines of text will be output?

3

What two-symbol sequence outputs the percent symbol in fprintf?

%%

Enter the formatting operator that most directly matches the description, such as %e for scientific-notation with lower-case e, or %-.2f for left-aligned fixed point with 2 digits after the decimal point. Fixed-point occupying a minimum of 8 digits, left-aligned, with 2 digits to the right of the decimal point.

%-8.2f

Enter the formatting operator that most directly matches the description, such as %e for scientific-notation with lower-case e, or %-.2f for left-aligned fixed point with 2 digits after the decimal point. Fixed-point with 4 digits to the right of the decimal point.

%.4f

Enter the formatting operator that most directly matches the description, such as %e for scientific-notation with lower-case e, or %-.2f for left-aligned fixed point with 2 digits after the decimal point. Scientific notation

%e or %E

Enter the formatting operator that most directly matches the description, such as %e for scientific-notation with lower-case e, or %-.2f for left-aligned fixed point with 2 digits after the decimal point. Fixed-point notation

%f

Either %f or %e, whichever is shorter

%g or%G

The following function purposely violates good practice in order to test understanding of the underlying concepts of a function: function out = PlusOne( inVar ) inVar = inVar + 1; out = inVar; end What is the value of inVar in the base workspace after executing:inVar = 1; out1 = PlusOne(inVar);

1

The following function purposely violates good practice in order to test understanding of the underlying concepts of a function: function out = PlusOne( inVar ) inVar = inVar + 1; out = inVar; end What is the value of inVar in the base workspace after executing:inVar = 1; inVar = PlusOne(inVar);

2

Enter the formatting operator that most directly matches the description, such as %e for scientific-notation with lower-case e, or %-.2f for left-aligned fixed point with 2 digits after the decimal point. What will fprintf('%.3f', 99.7379) display?

99.738

A comment is only valid if preceded by a MATLAB statement on the same line. T or F?

False

A local function can appear anywhere in a script. True or False

False A local function must be at the end of the script.

Given the following script saved in file CostDrive.mlx: miles = 100; costPerMile = 0.30; cost = miles * costPerMile; The variables created by the script are eliminated from the base workspace after the script runs. T or F?

False A script may create variables, which persist in the base workspace even after the script finishes running.

A second % ends a comment, thus enabling a statement to appear after a comment on a line, as in:% Increment total % total = total + 1; T or F?

False All text to the right of the first % is ignored, including the second % and everything after.

Given the following script saved in file CostDrive.mlx: miles = 100; costPerMile = 0.30; cost = miles * costPerMile; Running the script results in 30 being printed in some form to the command window. T or F?

False Notice that last statement ends with a semicolon. Thus this script prints no output.

Given the following script saved in file CostDrive.mlx: miles = 100; costPerMile = 0.30; cost = miles * costPerMile; The command line statement to run the script is: CostDrive.mlx True or False?

False The .mlx must be omitted. The correct statement is CostDrive.

The script testScript contains a local function fixEverything. The function fixEverything can be called from the command line. T or F?

False A local function can only be called from within the script that contains the function.

Each script has a workspace dedicated to that script. T or F?

False All scripts share the base workspace.

For the function definition beginning as shown below, are the following function calls likely to behave as a programmer intended? function [ surfaceArea, baseArea, vol ] = ConeVals ( radius, height ) [ baseArea, surfaceArea, vol ] = ConeVals ( rds, hght ); Yes or no?

No The programmer likely reversed the result variables baseArea and surfaceArea.

For the function definition beginning as shown below, are the following function calls likely to behave as a programmer intended? function [ surfaceArea, baseArea, vol ] = ConeVals ( radius, height )

No The surfaceArea output will be written into vol, which is likely not what the programmer intended.

A function provides isolation between 1) the names used for the inputs and outputs defined in the function, and 2) the variable names used in the program segment calling the function. True or False

True

In MATLAB, the % character is the only character that indicates a comment. T or F?

True

The base workspace stores variables that are created at the command line. T or F?

True

Given the following script saved in file CostDrive.mlx: miles = 100; costPerMile = 0.30; cost = miles * costPerMile; Entering the following command line is allowed:CostDrive; CostDrive T or F?

True A script may be run multiple times. And a script's name may be followed by a semicolon, which has no effect. In this case, the script would run twice.

For the function definition beginning as shown below, are the following function calls likely to behave as a programmer intended? function [ surfaceArea, baseArea, vol ] = ConeVals ( radius, height ) [ surf, base, vol ] = ConeVals ( rds, hght ); Yes or No?

Yes

For the function definition beginning as shown below, are the following function calls likely to behave as a programmer intended? function [ surfaceArea, baseArea, vol ] = ConeVals ( radius, height ) [ surfArea ] = ConeVals ( rds, hght ); Yes or No?

Yes

Complete the following statements using the format specification % - fieldWidth.precision convChar . To right justify the output, _______. a. no conversion specification is needed. b. a + must follow the %.

a. no conversion specification is needed.

Complete the following statements using the format specification % - fieldWidth.precision convChar . Precision is the number of digits to the right of the decimal point that _______. a. will be displayed at most. b. will always be displayed.

a. will always be displayed

Complete the following statements using the format specification % - fieldWidth.precision convChar . fieldWidth _______. a. is the maximum field width that will be displayed b. is the minimum field width that will be displayed

b. is the minimum field width that will be displayed

Referring to a function name elsewhere is known as a function _______.

call

A function is created by a function _______.

definition

Write a statement using the disp function. End with a semicolon. Output the value of a variable named distance.

disp(distance);

Type a statement (end with ;) to print the value of a variable named width as a decimal integer.

fprintf("%d", width);

Complete the fprintf function call to print the value of variable oceanDepth. frprintf("Depth is %f", ???? );

fprintf("Depth is %f", oceanDepth);

Type the formatting operator to display numMeters as a floating-point variable. fprintf("Meters: ??? ", numMeters);

fprintf("Meters: %f", numMeters);

Complete the fprintf function call to print the value of variable houseWidth and houseHeight. fprintf("Width : %f, height: %f.", ???? );

fprintf("Width: %f, height : %f.", houseWidth, houseHeight);

Type the first line of a function definition for a function named CubeNum with input xVal and output yVal .

function yVal = CubeNum (xVal)

What function obtains a number from a user?

input

Complete the statement that prompts the user with "Enter your age: " and assigns the variable userAge with the user-entered value. userAge =

input("Enter your age: ")

Logarithm to base e

log

Common logarithm

log10

Write a statement that assigns variable myNum with the result of a call to the function defined below with arguments 3 and 9function o1 = CalcR( i1, i2 )

myNum = CalcR(3, 9)

Assign measuredAngle with the sine of sunAngle plus cosine of sunAngle. sunAngle is in degrees. measuredAngle =

sind(sunAngle) + cosd(sunAngle)

Assign travelDist with the square root of milesEstimate. travelDist =

sqrt(milesEstimate);

Assign resultVal with the tangent of sunAngle. sunAngle is in degrees. resultVal =

tand(sunAngle)

Complete the statement to obtain a string from the user rather than a number. userName =string(input("Sally",

userName =string(input("Sally", "s"));


Kaugnay na mga set ng pag-aaral

Industrial Economics questions- Everything

View Set

KIV/ZI 1. ročník FEK, Teorie ke zkoušce ze ZI

View Set

ECO - Ch.18 - Open-Economy Macroeconomics: Basic Concepts

View Set

Political Ideologies "Nationalism" Chapter 6

View Set

Ch 7 Intrest Groups and Political Parties

View Set

Chapter 7: Requirements -> Behavior Driven Design

View Set

VIRGINIA v. BLACK (538 U.S. 343)

View Set