step equations forward in time for in range(n_t) [ + [ndt* [nv[ + [ndt*omega** * [nfig plt figure( plt plot(tu' -'tx_ *cos(omega* )' --'fig legend(( )('numerical''exact')'upper left'plt xlabel(' 'plt show(plt savefig('tmp pdf')plt savefig('tmp png'(see file osc_fe py since we already know the exact solution as td cos !twe have reasoned as follows to find an appropriate simulation interval oe and also how many points we should choose the solution has period =(the period is the time difference between two peaks of the tcos ! curve simulating for three periods of the cosine functiont and choosing such that there are intervals per period gives = and total of = intervals the rest of the program is straightforward coding of the forward euler scheme figure shows comparison between the numerical solution and the exact solution of the differential equation to our surprisethe numerical solution looks wrong is this discrepancy due to programming error or problem with the forward euler methodfirst of alleven before trying to run the programyou should sit down and compute two steps in the time loop with calculator so you have some intermediate results to compare with using dt : and we fig simulation of an oscillating system