MATLAB: Bode and Nyquist plots of FRF as function of operational frequency

Control System Toolboxfrdlti

I have a function for which I need to create a Bode plot and Nyquist Plot. The function describes a rotor, and is as follows. I'v built it up in parts – Hxx is a function of w (omega). k=spring stiffness, c=damping coefficient, l=length of shaft, I=moment of inertia, J=Diametral Inertia, W=rotational speed(rad/s), w=an array of frequencies between w=0:100:30000
``n1=k*(l^2);n2=w.*(i*c*(l^2));n3=w.^2.*I;d1=(k^2)*(l^2);d2=w.*(2*i*c*k*(l^2));d3=(w.^2).*((c^2*l^2)+(2*I*k)+(W*J/l)^2);d4=(w.^3).*(2*i*c*I);d5=(w.^4).*((I/l)^2);Hxx=(n1+n2-n3)./(d1+d2-d3-d4+d5);``
I can happily perform the following plots 1. plot(w, Hxx);
and
``realHxx=real(Hxx);imagHxx=imag(Hxx);% Calculate the magnitudemag=sqrt(realHxx.^2+imagHxx.^2);plot(w, mag);``
but I am now stuck as to how to produce a Bode and Nyquist plot. I suspect it is something with how to convert the function into an LTI model using frd, but I'm simply out of my depth with the documentation and cannot see how to proceed. Can anyone help please.
Don Howard

You can simply create an frd object:
``sys=frd(Hxx,w);bode(sys,w);nyquist(sys,w);``
Another option is instead of manually calculating the frequency response like you do, simply create a transfer function describing your system.
``s=tf('s'); %laplace transform variable``
Now modify your code to replace w with s. Also get rid of dot operations, you do not need them anymore:
``n1=k*(l^2);n2=s*(c*(l^2));n3=(s^2)*I;d1=(k^2)*(l^2);d2=s*(2*c*k*(l^2));d3=(s^2)*((c^2*l^2)+(2*I*k)+(W*J/l)^2);d4=(s^3)*(2*c*I);d5=(s^4)*((I/l)^2);Hxx=(n1+n2+n3)./(d1+d2+d3+d4+d5);``
I am not sure if W in d3 is the same as w. If it is, replace with s as well.
Now Hxx is a transfer function object.
Bode plot:
``bode(Hxx,w);``
Nyquist plot:
``nyquist(Hxx,w);``