# Matrix discretisation routine in C

Looking for the EFFICIENT algorithm implimented in C.
###### Who is Participating?

Commented:
Here it goes...
If you don't understand terminology...let me know..

c     returns the discretized state and input transition matrices

subroutine discret(a,b,delt,phi,gam,nord,ni)
implicit real*8(a-h,o-z)

dimension si(100,100),q(100,100),sb(100,100),prod(100,100)
dimension a(100,100),b(100,15)
dimension phi(100,100),gam(100,15)

do i=1,nord
q(i,i)=1.0
si(i,i)=q(i,i)
end do

do k=150,1,-1
if(k.eq.1) then
call matmul(si,b,nord,nord,ni,sb,100,100,100)
do i=1,nord
do j=1,ni
gam(i,j)=sb(i,j)*delt
end do
end do
call matmul(a,si,nord,nord,nord,prod,100,100,100)
do i=1,nord+1
do j=1,nord+1
phi(i,j)=prod(i,j)*delt+q(i,j)
end do
end do
else
call matmul(a,si,nord+1,nord+1,nord+1,prod,100,100,100)
do i=1,nord+1
do j=1,nord+1
si(i,j)=q(i,j)+prod(i,j)*delt/float(k)
end do
end do
endif
end do

return
end

c     _______________________________________________________________________________
c     subroutine to obtain the product of two matrices

subroutine matmul(a2,b2,m3,n3,iq,c1,ia,ib,ic)
implicit real*8(a-h,o-z)

dimension a2(ia,1),b2(ib,1),c1(ic,1)

do i=1,m3
do j=1,iq
c1(i,j)=0.0
do k=1,n3
c1(i,j)=c1(i,j)+a2(i,k)*b2(k,j)
end do
end do
end do

return
end
c     _______________________________________________________________________________

0

Commented:
state-space matrices?
0

Author Commented:
yes
0

Commented:
If you have access to MATLAB, have a look at MATLAB c2d command. They use matrix discretization using matrix exponentials but for you it will be very difficult to implement.

I know 3 routines do this. The good one is in Fortran (not in C) and it is easy to understand. I'll get it tomorrow.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.