Using summation and series to create a function to analyse and find error

1 vue (au cours des 30 derniers jours)
Richard Ledford
Richard Ledford le 30 Jan 2022
Réponse apportée : Binaya le 19 Oct 2023
I have a series of 10^(N-1) minus a summation of k=1 to 10^(N) of 0.1. I havn't worked with sums and series in a while and was wondering how to get exact value of N and what ever information you could give on composing the function with a for loop. I think that might help me figure out the function I need to create in my project. I have seen a lot of information on summations and how to put into a script in matlab, but I have found nothing on how I can do this with a power of N on the upper limit. Thankyou in advance. Any information you can provide would be helpful. P.S. Yes, I have looked up how to do summations in matlab and have not yet found how to do this particular problem. I know I need to use a for loop.

Réponses (1)

Binaya
Binaya le 19 Oct 2023
Hi Richard,
Based on your description, you would like to develop a MATLAB code using for loop for the series 10^(N-1) and a summation of k=1 to 10^(N) of 0.1, and take its difference.
Please find the below algorithm as a possible solution to your query:
  1. Initialize sum1 and sum2 as 0
  2. Initialize a value of N
  3. Start a for loop from 1 to N
  4. Update sum1 by incrementing it with 10^(k-1)
  5. After the for loop, update sum2 as 0.1*10^N as using for loop here would increase the time complexity exponentially.
  6. Finally take the difference of sum1 and sum2.
Please refer to the below Mathworks documentation for more reference:
  1. For loop: https://www.mathworks.com/help/matlab/ref/for.html
I hope this helps.
Regards
Binaya

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by