MATLAB Answers

Need some help with a function and With my code

1 view (last 30 days)
Hello!
I need some help. I got this question that im trying to answer......Please let me know How you would do this problem. I am so lost.
Leibnitz (the other Calculus guy) proved that the following infinite alternating series converges (very slowly) to pi. You are going to investigate just how slowly.
Create a function named partsum, that calculates the sum of a given number of terms (i.e., the Nth partial sum)
In the function, create a vector of terms (sequence) that is then added to determine the sum. The function should take as input a scalar N (not a vector) and return two outputs, the sum and the vector of terms.
In my .m file I will need to call the function for the values N = 5, 50, 500, and 5000, and determine the error for each. Use the table function to report your results.
Your output to the console should look like this:
Terms Error
_____ ________
5 0.19809
50 0.019998
500 0.002
5000 0.0002
Please let me know ASAP
Thank you
Daniel
  6 Comments
Walter Roberson
Walter Roberson on 18 Jul 2021
You got a response within 8 minutes. A possibility of a complete solution before an exam finished has more value than no solution at all, correct?
People do post exam questions while they are in the middle of writing exams.
Well think whatever you want
I have answered more than 50000 Questions. I have seen a lot of homework questions posted, and this was definitely a homework question.
I have also seen a number of cases where someone swears that something is not a homework question, but then the next day someone else posts the exact same question, and when this is pointed out the second person says something like, "Oh yes, that other person is in the same class as I am."

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 18 Jul 2021
MATLAB is quite versatile with respect to prpblems like this, so it does not require explicit loops to create the terms of that series (although you can code the terms using loops if you so desire).
Since this is not a homework problem, one approach would be —
k = 7;
kv = 1:k;
parts = (-1).^(kv-1)./(2*kv-1)
parts = 1×37
1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 0.0270 -0.0256 0.0244 -0.0233 0.0222 -0.0213 0.0204 -0.0196 0.0189 -0.0182 0.0175 -0.0169
S = 3.1686
Then use the appropriate function to calculate the sum of the series.
See the documentation section on Vectorization to understand how this example code works, and the reason it works.
.
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by