MATLAB: How to find certain point (ex. maximum y value, or certain y value with respect to certain x value) from a function/plot I made

functionmaximumplot

So here is the code:
M=300;
K=21000;
C=2000;
A=0.2;
wn=sqrt(K/M);
zeta=C/(2*sqrt(M*K)); % these are all constants
syms w
fplot(sqrt(wn^4+(2*zeta*wn*w)^2)/sqrt((wn^2-w^2)^2+(2*zeta*wn*w)^2),[0 100])
title('|G(jw)| vs w')
xlabel('w (rad/s)')
ylabel('|G(jw)|')
I am trying to find the maximum |G(jw)| value and the relative w value, and am also trying to find when |G(jw)|=0.1, what is the value of w.
Thanks in advance!

Best Answer

Use the max function and the interp1 function:
M=300;
K=21000;
C=2000;
A=0.2;
wn=sqrt(K/M);
zeta=C/(2*sqrt(M*K)); % these are all constants
syms w
hp = fplot(sqrt(wn^4+(2*zeta*wn*w)^2)/sqrt((wn^2-w^2)^2+(2*zeta*wn*w)^2),[0 100]);
title('|G(jw)| vs w')
xlabel('w (rad/s)')
ylabel('|G(jw)|')
xd = get(hp, 'XData');
yd = get(hp, 'YData');
[maxGjw,idx] = max(yd);
Gjw01 = interp1(yd(idx:end), xd(idx:end), 0.1);
fprintf('Maximum G(j%.2f) = %.2f\nG(j%.2f) = 0.1\n', xd(idx),maxGjw,Gjw01)
to get:
Maximum G(j7.47) = 1.66
G(j68.15) = 0.1