MATLAB: Is the MATLAB’s bode plot wildly off

bode plotcontrolControl System ToolboxMATLABtheory

I will give out all the details in case it is relevant. I have a MIMO state space system. I find its bode plot using MATLAB and separately using Mathematica. The plot from MATLAB is wildly off compared to the correct bode plot. However, the Mathematica plot is quite close to the correct one. Here's the interesting thing. The transfer function whose bode plot is being taken in both the softwares is calculated to be the same. Have I made some mistake or is it numerical errors contributing to the problem? Here is relevant part of my code:
A=[0,0,0,0,1,0,0,0;
0,0,0,0,0,1,0,0;
0,0,0,0,0,0,1,0;
0,0,0,0,0,0,0,1;
-297.3,163.5,0,0,0,0,0,0;
162.9,-267.2,104.2,0,0,0,0,0;
0,57.8,-74.2,16.4,0,0,0,0;
0,0,16.4,-16.4,0,0,0,0];
B=[0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
131.4,0.046,0,0,0;
0,0,0.045,0,0;
0,0,0,0.025,0;
0,0,0,0,0.25];
S=[1,0,0,0,0,0,0,0;
0,0,0,1,0,0,0,0];
D=zeros(2,5);
sys=ss(A,B,S,D)
systf=tf(sys);
s1a1=systf(1,2);
bode(s1a1);
I have attached the plots.
Upper one is MATLAB and the other Mathematica

Best Answer

This is a MIMO (5x2) system. Be careful that you plot the same input-outpair in MATLAB as Mathematica.
The Mathematica plot is Input 1 to Output 1 (or so it appears). So forget about the conversion to the transfer function and just do this:
[mag,phs,w] = bode(sys);
mag11 = squeeze(mag(1,1,:)); % Choose Input(1) To Output(1)
figure
semilogx(w, 20*log10(mag11))
xlabel('Frequency (rad/s)')
ylabel('Magnitude (dB)')
title('Input_1 To Output_1')
That plot looks to me to be the same as the Mathematica plot, other than the Mathematica plot being in terms of Hz (so Mathematica knows something MATLAB doesn’t.).
.