@Vostok1,
Please put any future code snippets in code tags (the first item, <>, in the format menu).
I can't see anything major wrong with your code, except that to see any very significant output you will have to enter quite a high frequency. (Because you have gone up to t = 2ms or 0.002 s, you would need a frequency of 500 Hz to get a single cycle out of that loop; that's ten times the mains frequency in Britain).
Without a voltage offset or phase shift I get the correct single cycle.
Note that, although you might think the nodal values in the cycle should be exactly 0.0, it is quite likely that you will see numbers like 1.2246e-016. This is VERY small:
0.00000000000000012246
which you will appreciate is immeasurably different from 0. The difference is simply because floating-point numbers can only be stored to a finite accuracy (about the 14th sig fig for doubles).
So, I see nothing particularly wrong with your code, but you may need to choose realistic input values - especially for frequency.
To improve it, I suggest:
- working in SECONDS, rather than milliseconds, if possible;
- reducing the number of brackets in that mathematical expression;
- using an integer as a for-loop variable; so if i is the for-loop variable then t = i * dt, where dt is a timestep between outputs;
- if you are going to plot it, then the best idea would be to output two columns - time and voltage - by changing your output line to
cout << t << '\t' << vT << endl;
Then, if you redirect output to file you can plot it with a graph-plotting package like gnuplot. This is a gnuplot output for f=500, V = 2, D = 2, theta = 90:
https://imgur.com/a/zIVnaNZ
and that is correct for those parameters.