setting up infinite sequence and plotting

29 visualizzazioni (ultimi 30 giorni)
Robert
Robert il 29 Giu 2024
Risposto: Prathamesh il 5 Lug 2024
How do I set up and plot:
Sum (n=0 to infinity) (n^3+1)
Thank you
  1 Commento
John D'Errico
John D'Errico il 29 Giu 2024
Modificato: John D'Errico il 29 Giu 2024
What have you tried? If nothing, then why not? Make an effort.
Of course, you may need to consider the series you show grows rapidly to infinity. So I might guess your question does not even show the series you actually want to form. Perhaps you mean the sum of 1/(n^3+1), not the sum of (n^3+1). That is convergent, apparently to:
vpa(ans)
ans =
1.6865033423386238859646052121869

Accedi per commentare.

Risposte (3)

sai charan sampara
sai charan sampara il 30 Giu 2024
Hello Robert,
I am assuming that you want to sum 1/(n^3+1) and not n^3+1 since the sum for n^3+1 tends to infinity as n moves to infinty. The sum of 1/(n^3+1) converges to a value as n tends to infinity. You can try doing this by calculating the value of the sum for each n value in a "while" loop. You can store the previous and current sum values. Then you can decide a tolerance value within which if there is no change you can accept the sum as converged value. It can be done similar to the code shown:
old_sum=sym(0);
new_sum=sym(1);
data=new_sum;
n=1;
tol=0.000001;
while((new_sum-old_sum)>tol)
old_sum=new_sum;
new_sum=new_sum+(1/(n^3+1));
n=n+1;
data=[data,new_sum];
end
vpa(old_sum)
ans = 
1.6864528398592121974925758815338
vpa(new_sum)
ans = 
1.6864538398582121984926371784164
plot(0:n-1,data)
You can decrease the "tol" (tolerance) value for more accurate results. Here is the link to documentation of "vpa":

tom
tom il 5 Lug 2024
  1. Define the Sequence: Decide on the mathematical formula or rule that generates the sequence.
  2. Generate Terms: Compute the terms of the sequence up to a reasonable number (since we can't truly generate an infinite number of terms).
  3. Plot the Sequence: Visualize the terms using a plot.
For demonstration, I'll consider a few common types of sequences and plot them:
  1. Arithmetic Sequence: A sequence in which each term after the first is obtained by adding a constant difference to the previous term. an=a+(n1)da_n = a + (n-1)dan=a+(n1)dwhere aaa is the first term and ddd is the common difference.
  2. Geometric Sequence: A sequence in which each term after the first is obtained by multiplying the previous term by a constant ratio. an=arn1a_n = ar^{n-1}an=arn1where aaa is the first term and rrr is the common ratio.
  3. Harmonic Sequence: A sequence in which each term is the reciprocal of an arithmetic sequence. an=1na_n = \frac{1}{n}an=n1
Let's plot the first 50 terms of each of these sequences.Arithmetic Sequence
  • First term a=1a = 1a=1
  • Common difference d=2d = 2d=2
Geometric Sequence
  • First term a=1a = 1a=1
  • Common ratio r=2r = 2r=2
Harmonic Sequence
  • an=1na_n = \frac{1}{n}an=n1
I'll generate and plot these sequences in Python.
Here are the plots for the three different types of sequences:
  1. Arithmetic Sequence (an=1+(n1)×2a_n = 1 + (n-1) \times 2an=1+(n1)×2): The terms increase linearly.
  2. Geometric Sequence (an=1×2(n1)a_n = 1 \times 2^{(n-1)}an=1×2(n1)): The terms increase exponentially.
  3. Harmonic Sequence (an=1na_n = \frac{1}{n}an=n1): The terms decrease and approach zero as nnn increases.

Prathamesh
Prathamesh il 5 Lug 2024
project in wed papge

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by