# How do I create a graph of the phase angle and response of a harmonic excitation in Matlab?

In my course of dynamics of structures, I am struggling with some basic principles. As a practice, I am plotting (or attempting to plot) the curves that are shown in the course book, with the help of Matlab. For example, I want to plot the phase angle theta as a function of beta, the dimensionless frequency, for a damped SDOF. The code I have is the following:

%Stiffness of the spring in [N/m]
k = 1;
%Mass in [kg]
m = 1;
%Damping constant in [Ns/m]
c = 0.1;
%Initial displacement in [m]
u_0 = 0;
%Initial velocity in [m/s]
v_0 = 0;
%%
omega_res = sqrt(k/m);
%Resonance frequency in [Hz]
f_res = (omega_res)/(2*pi);
%Eigenperiod in [s]
T_res = 1/f_res;
%%
%Critical damping in [Ns/m]
c_c = 2*sqrt(k*m);
%Damping ratio in [/]
xi = c/c_c;
%%
omega_d = omega_res * sqrt(1-xi^2);
%Damped eigenfrequency for strongly damped system in [rad/s]
omega_hat = omega_res * sqrt(xi^2-1);
%%
%Timevector
t = 0:0.1:100;
%Betavector
beta_v = 0:0.001:4;
%D as a function of beta
D = 1./sqrt((1-beta_v.^2).^2+(2*beta_v.*xi).^2);

plot(beta_v,D)
axis([0 4 0 10])
xlabel('Dimensionless frequency [-]')
ylabel('Dynamic amplification factor [-]')

%theta as a function of beta
theta = atan((2*beta_v*xi)./(1-beta_v.^2));

figure
plot(beta_v,angle(theta),'m')
axis([0 4 0 pi])
grid on
xlabel('Dimensionless frequency [-]')


But plotting gives me the curve of an undamped SDOF. The curve I get: The plot I am supposed to get: Does anyone have a clue what is wrong in my approach?

A second struggle occurs when you want to plot the the response for a particular beta. The curve I achieved was not what I expected. My code is the following:

%Response
beta_a = 0.2;
D_a = 1./sqrt((1-beta_a.^2).^2+(2*beta_a.*xi).^2);
theta_a = atan((2*beta_a*xi)./(1-beta_a.^2));
p_hat = 1;
omega = beta_a.*omega_res;
u_p = p_hat/k.*D_a.*exp(i.*(omega.*t-theta_a));
B = u_0 - p_hat./k.*D_a.*exp(-i.*theta_a);
A = (v_0 + xi*omega_res*B - p_hat/k*D_a.*i*omega*exp(-i.*theta_a))/omega_d;
u_h = exp(-xi.*omega_res.*t).*(A.*sin(omega_d.*t) + B.*cos(omega_d.*t));
u = u_p + u_h;
figure
plot(t,real(u))
grid on
xlabel('Time [s]')
ylabel('Displacement [m]')


Can anyone help me with this line of thought? What's wrong?

• It would help if you include pictures of what you expect the responses to be and what you're actually getting from your code.
– Paul
Feb 21 '16 at 14:38
• I am not allowed to post more than two pictures, so I included the two of the phase angle. Feb 21 '16 at 21:56
• Your code for plotting the phase angle seems to be wrong. Could you add that to your question? Otherwise the rest of the code is OK. See my answer below. Feb 22 '16 at 22:24
• I added the missing code for plotting the phase angle. Feb 23 '16 at 20:19

With your code, and with $c = 0.3$, I get the following results: The amplitude and phase look OK. But the displacement does not show any damping. To see why read on below.

I'm not sure about your notation. So the equations below may differ from those in your textbook.

ODE

The ODE you are trying to solve is $$\ddot{u} + 2\xi\omega_{\text{res}}\dot{u} + \omega_{\text{res}}^2 u = \frac{\hat{p}}{m}\text{Re}\left[\exp(i\omega t)\right]$$ where $$\xi = \frac{c}{c_c} ,~~ c_c = 2 m \omega_{\text{res}}, ~~ \omega_{\text{res}} = \sqrt{\frac{k}{m}}$$ and $c$ is the damping factor, $k$ is the stiffness, $m$ is the mass, $\omega$ is the forcing frequency.

Homogeneous solution

The homogeneous solution is $$u_h = A\,\exp(-\xi\omega_{\text{res}} t)\sin(\omega_d t + \phi_d)$$ where $\phi_d$ is a phase and $$\omega_d = \omega_{\text{res}}\sqrt{1 - \xi^2}$$

Notice that the exponential decay term occurs only in the homogeneous solution.

Particular solution

The particular solution is $$u_p = \frac{\hat{p}}{k} \frac{\text{Re}\left[\exp[i(\omega t - \phi)]\right]}{\sqrt{\left[1 - \beta_a)^2\right]^2 + \left[2\xi\beta_a\right]^2}}$$ where $$\beta_a = \frac{\omega}{ \omega_{\text{res}}}, ~~\tan\phi = \frac{2\xi\beta_a}{1 - \beta_a^2} \,.$$

• Your critical damping coeff $c_c = 2\sqrt(k m) = 2 m\sqrt{k/m} = 2 m \omega_{\text{res}}$. The damping coeff is higher just to make the damping more obvious in the figures. When using the initial condition to find $A$ and $B$ make sure that you use $u = u_h + u_p$. The $\phi_d$ term comes if you write your equation in the compact form in the updated answer. Feb 23 '16 at 20:52
{"ft_lang_label":"__label__en","ft_lang_prob":0.7291144,"math_prob":0.9986989,"size":2258,"snap":"2021-43-2021-49","text_gpt3_token_len":739,"char_repetition_ratio":0.1122449,"word_repetition_ratio":0.006006006,"special_character_ratio":0.35695305,"punctuation_ratio":0.17764471,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999745,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,4,null,4,null,4,null,4,null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-27T18:02:53Z\",\"WARC-Record-ID\":\"<urn:uuid:f9da3ba0-eb41-4bc6-858e-bd159872933d>\",\"Content-Length\":\"178545\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:18828e9d-3478-4692-9324-7ad3b52f49a3>\",\"WARC-Concurrent-To\":\"<urn:uuid:7c799104-23d6-4bf9-96a5-704f4f53ca62>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://engineering.stackexchange.com/questions/7534/how-do-i-create-a-graph-of-the-phase-angle-and-response-of-a-harmonic-excitation\",\"WARC-Payload-Digest\":\"sha1:Q6JSRFT5J32JNELYFWM76BXPP7WKOKYH\",\"WARC-Block-Digest\":\"sha1:N7O3FI4HTKLQUAB2RF7UWYBQUWSMNYNP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323588216.48_warc_CC-MAIN-20211027150823-20211027180823-00485.warc.gz\"}"}