In class we learned that, if terms added in a series continually decrease in size, the...

70.2K

Verified Solution

Question

Programming

In class we learned that, if terms added in a series continuallydecrease in size, the terms will eventually be too small to bestored by MATLAB. When a number is too small to be stored, welearned that such a situation is called underflow; in this case,MATLAB will just store it as 0. We also learned that a programcomputing such a series can terminate the loop when the next termto be added is equal to 0 (because of underflow).

It also turns out that, when each term is added to the runningsum in a series, the next term to be added will eventually be sosmall in size relative to the running sum, that this next term willnot even be picked up by the running sum- even before the termsreach underflow. In other words, even though additional terms areadded, the running sum will eventually stop changing - even beforeunderflow for the next term is reached.

In the script below, where indicated, write a segment of scriptthat uses one while loop (not vectors) to approximate sin(3.76)using the series, sin(x) approximately equals Sum i = 0 to n((-1)^i x^(2i+1))/(2i+1)!, for the largest n possible. In otherwords, add terms to the series just until running sum stopschanging. Furthermore,

i) Store the running sum into variable, runsum.

ii) Note that you will need to keep track of a current runningsum (runsum) and the previous sum ( call it sumold), which containsone less term. You will need to compare these in the condition of awhile loop, which will terminate once they are the same The finalvalue of runsum will contain up to and include the first term thatdoesn't change runsum, i.e. when runsum = sumold. Note that youwill need to initialize runsum and sumold with different values tostart the loop.

iii) Also, define variable, isum, to be a counter that will keeptrack of the number of terms added. The final value of isum will bethe number of terms in the final runsum.

Use only arithmetic operations and no built in functions (nor^). Use only one for loop.

format long

% write the code for part(a) here

%display final variables

runsum

isum

Answer & Explanation Solved by verified expert
4.3 Ratings (650 Votes)
The MATLAB script for the above problem isx 376 x initialised to 376runsum 0 all variables initialised to 0isum 0 sumold 1    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students