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

2 ビュー (過去 30 日間)
Richard Ledford
Richard Ledford 2022 年 1 月 30 日
回答済み: Binaya 2023 年 10 月 19 日
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.

回答 (1 件)

Binaya
Binaya 2023 年 10 月 19 日
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by