Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

% Do a step-by-step trace of each loop and determine what is % printed by the disp() functions. % Loop 1 disp('loop 1' ); xx

% Do a step-by-step trace of each loop and determine what is % printed by the disp() functions.

% Loop 1 disp('loop 1' ); xx = 10; while( xx > 3 ) xx = xx - 2; end disp(xx); % xx = ______

% Loop 2 disp( 'loop 2' ); total = 1; for( kk = 2 : 5 ) total = total + kk; end disp( [kk, total] ); % TC = _____, kk = _____, total = ______

% Loop 3 disp ('loop 3'); total = 100; for( kk = 20 : -5 : 1 ) total = total - kk; end disp( [kk, total] ); % TC = _______, kk = ______, total = _____

% Loop 4 disp('loop 4'); total = 0; vect=[20, 5, 12, 8]; for( kk = vect ) total = total + 2*kk; end disp( [kk, total] ); % TC = ______, kk = _____, total = ______

% Loop 5 disp( 'loop 5' ); total = 0; xx = [ 3, 6, 9, 12, 15, 18, 21 ]; for( kk = 1 : 2 : length(xx) ) total = total + xx(kk); end disp( [kk, total] ); % TC = ______ kk= _______, total = _______

% Loop 6 disp( 'loop 6' ); total = 0; xx = [ 2, 3, 5, 7, 11, 13, 17, 19 ]; for( kk = 1 : 2 : length(xx) ) xx(kk+1) = 2*xx(kk); end disp( xx ); % xx = [____, ____, ____, ____, ____, ____, ____, ____ ] % TC = _____________

7. Complete the function by filling in the blanks to estimate the infinite series, ? ? ? ? ?? ? ? n k n k k 1 1 1 1 lim . The function accepts one input parameter n, and outputs an estimate for the series. function [ ____________ ] = estOne( ____________________ ) % % input: nTimes, the number of times to repeat the running sum. % output: total, an estimate close to one. % % Begin by setting the running sum accumulator to zero. ______________ = 0; for kt = _____________ : ______________________ __________ = ___________ + __________________________; end end

8. Complete the function to implement the infinite series: ? ? ? ? ?? ? ? n k k n k x x 0 2 (2 )! cosh lim function [ ____________ ] = coshEst( ___________, ___________ ) % % inputs: 1. The x value input to cosh(x). % 2. the number of times, n, to repeat the running sum. % output: cosh(x). % use the factorial(2k) to compute (2k)! % % Begin by setting the running sum accumulator total to zero: ____________ = ____________ ; for kt = _________________ : _______________________ % Fill-in the needed steps for completing the calculation. end end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions