I am new to programming and try to calculate the values of A[t] for $$t$$ from 0 to 0.5 in steps of 0.025 as follows but it does not work;

Block[{\$RecursionLimit=Infinity},
Mass = m = 500000;
StiffnessCoefficient = k =300000000;
{NaturalFrequency = Sqrt[k/m], Period = 2*Pi/NaturalFrequency, FundamentalFrequency = 2*Pi}//N;
P0 = 5000000;
P[t_] := P0*Sin[FundamentalFrequency*t];
Δτ = 0.025;
A = 0;
A[t_] := A[t - Δτ] + P[t - Δτ]*Cos[FundamentalFrequency*(t - Δτ)] + P[t]*Cos[FundamentalFrequency*t];
Table[A[t], {t, 0.025, 0.5, 0.025}]
]

I also tried different looping structures using Do, For or While sequences but I don't understand how to achieve it.

Could you help me solve my problem please ?

The issue with your code is that you are indexing into A with real (floating point) numbers. Since these are never exact, there are values that cannot be computed. To fix, remove the Block[ ] and change:

Δτ = 25/1000;
Table[A[t], {t, 25/1000, 1/2, 25/1000}] // N

This indexes with exact numbers and so gives an answer.

• Thank you very much @bill s that is exactly what I wanted!
– Mav
Nov 24 '19 at 15:36
• Probably a more economical change (and possibly faster) is to change the definition of A to A[0.] Nov 25 '19 at 15:46
• @Carlo -- I don't think that works. The problem is that real/floating point numbers experience round off errors and once an error (no matter how tiny) occurs, you'll end up with undefined terms. Nov 26 '19 at 2:48
• You might be right, I only checked without the Block and the first two iterations were working. Nov 27 '19 at 7:26

Maybe this produces what you seek

P[t_] := 5000000 Sin[2. Pi t];
Δτ = 0.025;
Accumulate[
Table[
P[t - Δτ] Cos[2. Pi (t - Δτ)] + P[t] Cos[2. Pi t],
{t, Δτ, 0.5, Δτ}]
]
• Thank you for your help, but why isn't P evaluated in your piece of code @Henrick Schumacher ?
– Mav
Nov 24 '19 at 15:38
• I do not understand your question; P is evaluated. Maybe you are missing A? That's what Accumulate is good for. Nov 24 '19 at 17:38
• Sorry for that, I said that because I obtain {1. p[0.]+0.987688 p[0.025],1. p[0.]+1.97538 etc... instead of a list of the values I seek.
– Mav
Nov 24 '19 at 18:22
• With my code? Impossible. There is no lower case p. Nov 24 '19 at 18:34
• Please, restart the kernel (with Exit and Shift+Enter) and copy the code here into your notebook. Nov 24 '19 at 19:13