Rework lsim; fixes #2652 and #1104
Rework lsim; fixes #2652 and #1104

The previous implementation of lsim did not work for systems with a pole
at the origin, or with repeated poles.  This new version fixes all of
the (known) issues with lsim.

The new implementation uses the matrix exponential, like the old
implementation, but computes it using linalg.expm instead of by
diagonalization.  This solves the problem with repeated poles.  In
addition, the new implementation does not require inv(A) to compute the
forcing term, and it no longer fails for systems with a pole at the
origin.  Details of the algorithm are documented in the comments.

Note that there is already an lsim2 routine that fixes the above
problems.  However, it calls a generic ODE integrator, and can be
hundreds of times slower than the implementation here.

An important change with the new implementation is that the time vector
must now be evenly spaced.  Note that this same requirement is in the
MATLAB version of lsim.  One could modify this to allow for non-uniform
time samples, but this would slow down the algorithm, because the matrix
exponential would need to be recomputed whenever the timestep changes.
In addition, small, machine-precision-level differences in timestep
might trigger the matrix exponential to be recomputed when it is not
necessary.  Therefore, the implementation here checks whether timesteps
are approximately uniform using np.allclose(), and gives an error if
they are not.

Eric89GXL/scipy,piyush0609/scipy,mdhaber/scipy,Newman101/scipy,apbard/scipy,ndchorley/scipy,andyfaff/scipy,nonhermitian/scipy,person142/scipy,chatcannon/scipy,WillieMaddox/scipy,gdooper/scipy,pnedunuri/scipy,sauliusl/scipy,Kamp9/scipy,gdooper/scipy,surhudm/scipy,larsmans/scipy,newemailjdm/scipy,scipy/scipy,dominicelse/scipy,larsmans/scipy,gef756/scipy,mgaitan/scipy,pizzathief/scipy,mhogg/scipy,ilayn/scipy,person142/scipy,ales-erjavec/scipy,jjhelmus/scipy,behzadnouri/scipy,raoulbq/scipy,FRidh/scipy,felipebetancur/scipy,jamestwebber/scipy,kleskjr/scipy,sriki18/scipy,piyush0609/scipy,kleskjr/scipy,josephcslater/scipy,zaxliu/scipy,gfyoung/scipy,andyfaff/scipy,haudren/scipy,aeklant/scipy,sonnyhu/scipy,WarrenWeckesser/scipy,argriffing/scipy,aarchiba/scipy,endolith/scipy,minhlongdo/scipy,jonycgn/scipy,futurulus/scipy,haudren/scipy,richardotis/scipy,kalvdans/scipy,kalvdans/scipy,endolith/scipy,ilayn/scipy,Shaswat27/scipy,larsmans/scipy,giorgiop/scipy,matthew-brett/scipy,jonycgn/scipy,person142/scipy,gertingold/scipy,fernand/scipy,rgommers/scipy,sriki18/scipy,WarrenWeckesser/scipy,gertingold/scipy,richardotis/scipy,hainm/scipy,mtrbean/scipy,mtrbean/scipy,fernand/scipy,larsmans/scipy,aeklant/scipy,person142/scipy,mingwpy/scipy,nonhermitian/scipy,rgommers/scipy,andim/scipy,mingwpy/scipy,giorgiop/scipy,behzadnouri/scipy,vanpact/scipy,jonycgn/scipy,fernand/scipy,cpaulik/scipy,ilayn/scipy,sonnyhu/scipy,felipebetancur/scipy,lhilt/scipy,chatcannon/scipy,tylerjereddy/scipy,minhlongdo/scipy,FRidh/scipy,matthew-brett/scipy,zerothi/scipy,nonhermitian/scipy,nmayorov/scipy,newemailjdm/scipy,giorgiop/scipy,felipebetancur/scipy,matthew-brett/scipy,zerothi/scipy,apbard/scipy,grlee77/scipy,aarchiba/scipy,vberaudi/scipy,anielsen001/scipy,rmcgibbo/scipy,richardotis/scipy,pizzathief/scipy,mgaitan/scipy,mortada/scipy,pyramania/scipy,andyfaff/scipy,ChanderG/scipy,vanpact/scipy,felipebetancur/scipy,jamestwebber/scipy,befelix/scipy,pnedunuri/scipy,jseabold/scipy,zaxliu/scipy,aman-iitj/scipy,argriffing/scipy,trankmichael/scipy,richardotis/scipy,mgaitan/scipy,woodscn/scipy,minhlongdo/scipy,futurulus/scipy,richardotis/scipy,Srisai85/scipy,kleskjr/scipy,kalvdans/scipy,matthewalbani/scipy,jseabold/scipy,fredrikw/scipy,andim/scipy,befelix/scipy,ales-erjavec/scipy,jamestwebber/scipy,kleskjr/scipy,pyramania/scipy,haudren/scipy,chatcannon/scipy,josephcslater/scipy,vigna/scipy,aeklant/scipy,nmayorov/scipy,rgommers/scipy,njwilson23/scipy,Kamp9/scipy,Gillu13/scipy,matthew-brett/scipy,WarrenWeckesser/scipy,woodscn/scipy,rmcgibbo/scipy,giorgiop/scipy,piyush0609/scipy,chatcannon/scipy,Srisai85/scipy,ChanderG/scipy,Srisai85/scipy,mikebenfield/scipy,zxsted/scipy,nmayorov/scipy,lukauskas/scipy,fredrikw/scipy,hainm/scipy,jjhelmus/scipy,argriffing/scipy,WarrenWeckesser/scipy,mgaitan/scipy,matthewalbani/scipy,ales-erjavec/scipy,anntzer/scipy,raoulbq/scipy,mingwpy/scipy,Gillu13/scipy,WillieMaddox/scipy,argriffing/scipy,pizzathief/scipy,andim/scipy,rmcgibbo/scipy,rgommers/scipy,lhilt/scipy,aman-iitj/scipy,surhudm/scipy,giorgiop/scipy,trankmichael/scipy,Newman101/scipy,larsmans/scipy,ndchorley/scipy,grlee77/scipy,mhogg/scipy,bkendzior/scipy,petebachant/scipy,mtrbean/scipy,gfyoung/scipy,jor-/scipy,lukauskas/scipy,cpaulik/scipy,jor-/scipy,arokem/scipy,maniteja123/scipy,woodscn/scipy,aman-iitj/scipy,sauliusl/scipy,FRidh/scipy,pschella/scipy,aarchiba/scipy,jonycgn/scipy,anntzer/scipy,mortada/scipy,futurulus/scipy,zxsted/scipy,surhudm/scipy,WillieMaddox/scipy,endolith/scipy,Srisai85/scipy,perimosocordiae/scipy,woodscn/scipy,cpaulik/scipy,pyramania/scipy,arokem/scipy,WillieMaddox/scipy,tylerjereddy/scipy,Gillu13/scipy,nonhermitian/scipy,ilayn/scipy,ortylp/scipy,fredrikw/scipy,perimosocordiae/scipy,jseabold/scipy,jamestwebber/scipy,perimosocordiae/scipy,tylerjereddy/scipy,kleskjr/scipy,arokem/scipy,matthewalbani/scipy,grlee77/scipy,gfyoung/scipy,trankmichael/scipy,ilayn/scipy,raoulbq/scipy,gertingold/scipy,minhlongdo/scipy,minhlongdo/scipy,jjhelmus/scipy,Eric89GXL/scipy,vanpact/scipy,tylerjereddy/scipy,person142/scipy,pbrod/scipy,behzadnouri/scipy,jor-/scipy,apbard/scipy,sonnyhu/scipy,Shaswat27/scipy,mhogg/scipy,lhilt/scipy,pbrod/scipy,jseabold/scipy,gef756/scipy,sauliusl/scipy,perimosocordiae/scipy,pschella/scipy,fernand/scipy,niknow/scipy,josephcslater/scipy,vberaudi/scipy,pbrod/scipy,zerothi/scipy,zaxliu/scipy,Shaswat27/scipy,e-q/scipy,mgaitan/scipy,maniteja123/scipy,ChanderG/scipy,Newman101/scipy,andyfaff/scipy,josephcslater/scipy,Srisai85/scipy,mikebenfield/scipy,sauliusl/scipy,fredrikw/scipy,zxsted/scipy,gef756/scipy,scipy/scipy,niknow/scipy,Gillu13/scipy,Eric89GXL/scipy,mhogg/scipy,Newman101/scipy,ortylp/scipy,Gillu13/scipy,felipebetancur/scipy,niknow/scipy,zxsted/scipy,jjhelmus/scipy,perimosocordiae/scipy,giorgiop/scipy,aarchiba/scipy,jor-/scipy,jjhelmus/scipy,mingwpy/scipy,haudren/scipy,Srisai85/scipy,niknow/scipy,vigna/scipy,njwilson23/scipy,behzadnouri/scipy,hainm/scipy,kalvdans/scipy,arokem/scipy,newemailjdm/scipy,jakevdp/scipy,mtrbean/scipy,njwilson23/scipy,woodscn/scipy,FRidh/scipy,zerothi/scipy,hainm/scipy,sriki18/scipy,vberaudi/scipy,pbrod/scipy,Gillu13/scipy,WillieMaddox/scipy,pnedunuri/scipy,aman-iitj/scipy,mtrbean/scipy,bkendzior/scipy,mgaitan/scipy,newemailjdm/scipy,lhilt/scipy,jor-/scipy,jonycgn/scipy,befelix/scipy,ortylp/scipy,zaxliu/scipy,newemailjdm/scipy,pbrod/scipy,petebachant/scipy,gdooper/scipy,jakevdp/scipy,trankmichael/scipy,niknow/scipy,njwilson23/scipy,lukauskas/scipy,mingwpy/scipy,pschella/scipy,FRidh/scipy,pyramania/scipy,andyfaff/scipy,vanpact/scipy,mhogg/scipy,ndchorley/scipy,jseabold/scipy,anielsen001/scipy,scipy/scipy,cpaulik/scipy,nmayorov/scipy,dominicelse/scipy,rgommers/scipy,argriffing/scipy,aarchiba/scipy,ales-erjavec/scipy,mhogg/scipy,haudren/scipy,anntzer/scipy,anntzer/scipy,apbard/scipy,kalvdans/scipy,futurulus/scipy,Stefan-Endres/scipy,mortada/scipy,felipebetancur/scipy,zxsted/scipy,futurulus/scipy,trankmichael/scipy,ortylp/scipy,zxsted/scipy,zaxliu/scipy,pyramania/scipy,mtrbean/scipy,maniteja123/scipy,jakevdp/scipy,jakevdp/scipy,perimosocordiae/scipy,gef756/scipy,rmcgibbo/scipy,e-q/scipy,haudren/scipy,FRidh/scipy,raoulbq/scipy,maniteja123/scipy,minhlongdo/scipy,anielsen001/scipy,matthewalbani/scipy,mdhaber/scipy,mikebenfield/scipy,andyfaff/scipy,vigna/scipy,chatcannon/scipy,Stefan-Endres/scipy,endolith/scipy,e-q/scipy,ilayn/scipy,futurulus/scipy,mortada/scipy,fredrikw/scipy,Newman101/scipy,matthewalbani/scipy,newemailjdm/scipy,jonycgn/scipy,raoulbq/scipy,andim/scipy,josephcslater/scipy,apbard/scipy,matthew-brett/scipy,ortylp/scipy,behzadnouri/scipy,piyush0609/scipy,dominicelse/scipy,Stefan-Endres/scipy,chatcannon/scipy,petebachant/scipy,lukauskas/scipy,vanpact/scipy,WarrenWeckesser/scipy,sauliusl/scipy,petebachant/scipy,sauliusl/scipy,fredrikw/scipy,jamestwebber/scipy,cpaulik/scipy,mdhaber/scipy,jseabold/scipy,anntzer/scipy,anntzer/scipy,befelix/scipy,argriffing/scipy,grlee77/scipy,Shaswat27/scipy,scipy/scipy,bkendzior/scipy,hainm/scipy,e-q/scipy,lukauskas/scipy,larsmans/scipy,maniteja123/scipy,gdooper/scipy,Stefan-Endres/scipy,mortada/scipy,ndchorley/scipy,aeklant/scipy,fernand/scipy,surhudm/scipy,andim/scipy,maniteja123/scipy,piyush0609/scipy,petebachant/scipy,woodscn/scipy,rmcgibbo/scipy,sonnyhu/scipy,ales-erjavec/scipy,gertingold/scipy,grlee77/scipy,ortylp/scipy,Stefan-Endres/scipy,e-q/scipy,WarrenWeckesser/scipy,bkendzior/scipy,vigna/scipy,hainm/scipy,anielsen001/scipy,mdhaber/scipy,behzadnouri/scipy,ChanderG/scipy,Eric89GXL/scipy,zerothi/scipy,niknow/scipy,vberaudi/scipy,mdhaber/scipy,gertingold/scipy,dominicelse/scipy,mingwpy/scipy,mikebenfield/scipy,ChanderG/scipy,sonnyhu/scipy,petebachant/scipy,anielsen001/scipy,kleskjr/scipy,rmcgibbo/scipy,mikebenfield/scipy,befelix/scipy,ChanderG/scipy,surhudm/scipy,pnedunuri/scipy,endolith/scipy,mdhaber/scipy,lukauskas/scipy,surhudm/scipy,raoulbq/scipy,Kamp9/scipy,vberaudi/scipy,Kamp9/scipy,zerothi/scipy,sriki18/scipy,sriki18/scipy,njwilson23/scipy,Eric89GXL/scipy,zaxliu/scipy,Kamp9/scipy,ales-erjavec/scipy,ndchorley/scipy,aman-iitj/scipy,dominicelse/scipy,andim/scipy,Stefan-Endres/scipy,jakevdp/scipy,bkendzior/scipy,Kamp9/scipy,pschella/scipy,aeklant/scipy,gef756/scipy,pnedunuri/scipy,nmayorov/scipy,scipy/scipy,tylerjereddy/scipy,vberaudi/scipy,gfyoung/scipy,endolith/scipy,trankmichael/scipy,pschella/scipy,cpaulik/scipy,nonhermitian/scipy,gfyoung/scipy,ndchorley/scipy,fernand/scipy,piyush0609/scipy,arokem/scipy,Eric89GXL/scipy,gdooper/scipy,Newman101/scipy,pizzathief/scipy,pbrod/scipy,mortada/scipy,vanpact/scipy,anielsen001/scipy,njwilson23/scipy,pizzathief/scipy,pnedunuri/scipy,Shaswat27/scipy,vigna/scipy,gef756/scipy,sriki18/scipy,aman-iitj/scipy,WillieMaddox/scipy,richardotis/scipy,lhilt/scipy,Shaswat27/scipy,sonnyhu/scipy,scipy/scipy