MATLAB Answers

maximum value not evaluating

1 view (last 30 days)
I have tried to evaluate my function for it's maximum, but I keep failing. What am I missing here?
I realize this is a very basic calculus problem, but my function I am determing the max output power for has it's own set of variables that I am optimizing, and I think that is why I cannot use the function "handle"? I am sure my terminology is incorrect.
I get the correct plot, but I just want to spit out the value of the maximum of the plot (ymax value), which in the code I have labeled as P_ave_output(R_l_optimal). Shouldn't this give me the max value of the function?
clear all
syms omega t R_l s A_in Y
A_o = 3;
R_c = 40;
L_c = 0.051;
omega_in = 2*pi*f;
A = A_o*sin(omega*t);
%Theta from part a)
theta = 0.244;
%Spring coefficient (N/m)
k = 13660;
%Damping coefficient (N*s/m)
C_d = 0.07;
%Capacitance Assumption
%Impedance equations
Z1 = R_c+R_l+L_c*s+1/(s*C);
Z2 = C_d+k/s+M*s;
%From part a) transfer function
%Output voltage V_l
V_l = (theta*(Y*s)*R_l)/Z1;
%Input excitation force Z_in
%output voltage ratio to input force
Transfer_func = simplify(V_l/A_in);
Transfer_func(s) = vpa(simplify(V_l/A_in),5);
Transfer_func(omega) = subs(Transfer_func, {s},{1j*omega});
amplitude_TF = A_o*abs(Transfer_func(omega_in));
angle_TF = angle(Transfer_func(omega_in));
V_l_steady_state = amplitude_TF*(sin(omega_in*t+angle_TF));
P_ave_output = (amplitude_TF/(sqrt(2)))^2/R_l;
P_ave_diff = diff(P_ave_output);
P_ave_diff = simplify(P_ave_diff, 'Steps',500);
P_ave_max = P_ave_diff == 0;
R_l_optimal = vpa(abs((solve(P_ave_max, R_l))),3)
fplot(P_ave_output,[10 200])
xticks([10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200])
ylabel('Average Power (Watts)')
xlabel('Load Resistance R_l (Ohms)')


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 9 Jun 2020
Since ‘P_ave_output’ is not defined as function, MATLAB interprets the current syntax as a subscript.
Try this:
plotMax = vpa(subs(P_ave_output,{R_l},{R_l_optimal}),16)
plotMax =
R_l_optimal =


Shane Palmer
Shane Palmer on 9 Jun 2020
Thank you again. This worked well.
Star Strider
Star Strider on 9 Jun 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!