MATLAB Answers

How do I plot a graph when the parameter changes?

2 views (last 30 days)
clc, clear all
k_l = 26400; %Linear stiffness
m = 483; %Mass
l =0.5;
d =-0.1;
f_n = sqrt(k_l/m)/(2*pi); %Natural frequency
Om_array = linspace(0,20,40); %in rad/s-1
A_array = linspace(0,0.06,40);
[om_array, a_array] = meshgrid(Om_array, A_array);
Response_amp = zeros(size(Om_array));
T = 130;
x0 = [0,0];
for i=1:numel(Om_array)
for j=1:numel(A_array)
Om = om_array(i,j);
A = a_array(i,j);
k_s = -(k_l*(l-d))/(4*d); %Spring stiffness
f = @(t,x) [ x(2); ...
-(2*k_s*(x(1)-(A*sin(Om*t))))* ...
(sqrt((l-d)^2 + (x(1)-(A*sin(Om*t)))^2) - l)/ ...
(m*(sqrt((l-d)^2 + (x(1)-(A*sin(Om*t)))^2))) ];
[t, x] = ode45(f,[100,T],x0);
Response_amp(i,j) = (max(x(:,1)) - min(x(:,1)))/2;
% xval(i) = Om/(2*pi) ;
%% plot
ax = axes();
view([30 33]);
grid on
mesh(om_array/(2*pi),a_array,Response_amp) ;
xlabel('Frequency (Hz)')
ylabel('Excitation Amplitude (m)')
zlabel('Response Amplitude (m)')
Hi, all. This is the code of my ode45 function. If you run this code, you will see 3d plot graph (Frequency vs Excitation ampltidue vs Response amplitude). The maximum value of response amplitude will always occur at the maximum exciation amplitude. If we change the value of the parameter "l ", the maximum response amplitude will also change.
So, I wish to plot a graph (l vs the maximum response amplitude) when l is varied from 0 to 1.
Thanks for reading.


Sriram Tadavarty
Sriram Tadavarty on 27 Apr 2020
As far as i understand, you are looking for plotting the maximum value of the plot as a function of l. So, tried to place the attachment here. Please do have a look and let me know if you are looking for the same.
Thanking you.
donghun lee
donghun lee on 27 Apr 2020
Yes!! This is what I have been actually looking for! Thank you soooo much for your help Sriram!!
Sriram Tadavarty
Sriram Tadavarty on 27 Apr 2020
Glad that it is of help.
Placing the same in the answer.

Sign in to comment.

Accepted Answer

Sriram Tadavarty
Sriram Tadavarty on 27 Apr 2020
Hi Donghun,
This can be done by taking the maximum value of Response_amp and storing the values for each iteration of l. Then plot the maximum values with l.
Placed the same in the attachment.
Hope this helps.
Thanking you.

  1 Comment

donghun lee
donghun lee on 27 Apr 2020
Perfect! I appreciate your help again Sriram. :)

Sign in to comment.

More Answers (0)