How do I plot a graph when the parameter changes?

3 次查看(过去 30 天)
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) ;
end
end
%% plot
figure(1);
ax = axes();
view(3);
hold(ax);
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)')
set(gca,'FontSize',17)
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.
  3 个评论
donghun lee
donghun lee 2020-4-27
Yes!! This is what I have been actually looking for! Thank you soooo much for your help Sriram!!
Sriram Tadavarty
Sriram Tadavarty 2020-4-27
Glad that it is of help.
Placing the same in the answer.

请先登录,再进行评论。

采纳的回答

Sriram Tadavarty
Sriram Tadavarty 2020-4-27
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.
Regards,
Sriram

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Directed Graphs 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by