you have to calculate the camera position behind the object ( by a certain amount i.e. -40 in your case ) according to the object position/angle.
DBP commands to do this are newxvalue and newzvalue in relation to the object angle.
Unfortunately turn object does not return the angle from 0 to 360 degrees ( i think it's -90 to +90 )
Therefore it's better to rotate the object according to an angle.
Example:
(remmed code is useless)
MAKE OBJECT Box 4,10,10,20
POSITION OBJECT 4, 0,-8.7,0
rem Position Camera 0,2,0
rem Move Camera -40
make matrix 1,1000,1000,30,30
position matrix 1,-500,-10,-500
DO
rem Set Camera to Object Orientation 4
if spacekey()=1 then move object 4,0.1
rem if leftkey()=1 then turn object left 4,0.05
rem if rightkey()=1 then turn object right 4,0.05
if leftkey()=1 then oa#=wrapvalue(oa#-0.05)
if rightkey()=1 then oa#=wrapvalue(oa#+0.05)
yrotate object 4,oa#
ox#=object position x(4)
oz#=object position z(4)
cx#=newxvalue(ox#,oa#,-40)
cz#=newzvalue(oz#,oa#,-40)
position camera cx#,2,cz#
yrotate camera oa#
gosub printdata
LOOP
printdata:
set cursor 0,0
print "ox#= ",ox#
print "oz#= ",oz#
print "oa#= ",oa#
print
print "cx#= ",cx#
print "cz#= ",cz#
return