MATLAB: Script not producing the correct plot

transfer function script not working

Hi…
I need to simulate a signal in MatLab but I can't make my simple script to work properly.
The function is a Transfer Function of a given circuit.
The expression is the following
The script I'm trying to use to simulate this expression is:
if true
R1=100;
R2=1e3;
C=1e-6;
% fc=1/(2*pi*R*C);
f=1:1:1e4;
ter1=R2^2;
ter2=(2*pi.*f*C*R1*R2).^2;
ter3=(R1+R2).^2;
ter4=(2*2*pi.*f*C*R1*R2).^2;
mhf=(ter1+ter4)/(ter2+ter3);
mhf=power(mhf, 0.5);
% mod_hf=abs(hf);
% fase_hf=angle(hf);
figure(1);
subplot(2,1,1); plot(f,mhf); grid on;
title('Funcao de Transferencia do Filtro Passa-baixo RC')
xlabel('Frequencia (Hz)')
ylabel('|H(f)|')
% subplot(2,1,2); plot(f,fase_hf);grid on;
% xlabel('Frequency (Hz)')
% ylabel('arg[H(f)] (rad)')
end
I have calculated the result for a few frequencies in calculator and I fot the following values:
f=0Hz--> |H(f)| = 0.9091
f=50Hz--> |H(f)| = 0.9081
f=200Hz--> |H(f)| = 0.8932
f=500Hz--> |H(f)| = 0.8274
f=1000Hz--> |H(f)| = 0.7072
f=5000Hz--> |H(f)| = 0.5169
f=5MHz--> |H(f)| = 0.5
which matches an High-Pass Filter but I can't get the correct plot!!! Any help?

Best Answer

Change:
mhf=(ter1+ter4)/(ter2+ter3);
to:
mhf=(ter1+ter4)./(ter2+ter3);
and it works. You need to do element-by-element division as well.