Question
Problem 3: Numerical iterations using a while-loop (from in-lab) An essential technique in implementing numerical methods is to assess when to terminate an iterative algorithm.
Problem 3: Numerical iterations using a while-loop (from in-lab) An essential technique in implementing numerical methods is to assess when to terminate an iterative algorithm. This is fundamental of the numerical recipe introduced in class. Consider the sum of the squared of a discrete function f k k ( ), 1,2,3, , i.e., 2 1 ( ) N k f k . Determine the minimum number of terms in the summation when this sum exceeds a value minsum. In other words, find the minimum N for which 2 1 ( ) minsum N k f k . The iterative algorithm will also terminate if the number of terms in the summation exceeds a maximum number of terms (or iterations) maxitr. a) Briefly describe the pseudo-codes (i.e., flow of logic and operations) for the above algorithm. b) Develop a MATLAB function file (numerical solver) to execute the above iterative algorithm. Test your numerical solver on the example of f k k ( ) , minsum=1e4, and maxitr=20. Test again with minsum=2000, and maxitr=20. Also, perform benchmark test of your code. For convenience, complete the m-file hw01prob3 provided. Remember to change the name of the m-file provided from hw01prob3_part to hw01prob3 !!! Critical thinking: An important characteristic of this series is that every term in the series is the same, namely 2 f k( ) , but without the index (counter) advancing by one. To determine how many terms are needed in the summation, we can develop a while-loop which adds to the series one term at a time and terminates when the summation exceeds the value of minsum. Use the variable k as the counter. Thus, initialize k=0 and the series sum to be zero before the execution of the loop.
initial code:
function [total, N] = hw01prob3(fun,minsum,maxitr) %% [total, N] = hw01prob3(fun,minsum,maxitr) % This function evaluates the summation of the squared of a discrete % function f(k), k =1,2,3,... and terminates when the sum exceeds "minsum" % or when the number of terms (iterations) in the summation exceeds "maxitr". % It also outputs the minimum number of terms required in the summation % and the value of the summation. % % Inputs/Outputs: % fun = discrete function of k = 1,2,3,... % minsum = minimum non-negative real value that the summation must exceed % maxitr = maximum number of terms (or iterations) in the series summation % total = value of the series summation % N = the minimum number of terms required in the summation %% Initializations and checks if minsum
%% Execution of the algorithm while end N =
%% Conditions under which the loop may terminate before all conditions are satisfied % The loop may terminate before the summation exceeds minsum if N == maxitr && total
An essential technique in implementing numerical methods is to assess when to terminate an iterative algo!!!!!!!!. This is fundamental ofthe numerical lecipe', introduced in class Consider the sum of the squared of a discrete function f(k), k = 1,2,3,.. . , i.e., ( f(k)) Determine the minimum number of terms in the summation when this sum exceeds a value minsum. In other words, find the minimum N for which yfkminsum. The iterative algorithm will also terminate if the number of terms in the summation exceeds a maximum number of terms (or iterations) maxitr. a) Briefly describe the pseudo-codes (i.e., flow of logic and operations) for the above algorithm. b) Develop a MATLAB function file (numerical solver) to execute the above iterative algorithm. Test your numerical solver on the example of f(k)=k, mins um=1e4, and maxitr-20. Test again with minsum 2000, and maxitr-20._Also, perform benchmark test of your code For convenience, complete the m-file hw01prob3 provided. Remember to change the name of the m-file provided from hw01prob3_part to hw01prob3 !!! Critical thinking: An important characteristic of this series is that every term in the series is the same, namely (f(k), but without the index (counter) advancing by one. To determine how many terms are needed in the summation, we can develop a while-loop which adds to the series one term at a time and terminates when the summation exceeds the value of minsum. Use the variable k as the counter. Thus, initialize k-0 and the series sum to be zero before the execution of the loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started