thank you all!!
But I solved this way:
ESERCITAZIONE 1 - IGS 2018/2019
#Funzione di amplificazione A2
H = 10 # [m] Spessore strato
Vs = 200 # [m/s] Velocità onde S
D = 0.05 # [%] Smorzamento
Funzione di amplificazione A2
A2 <- function(f) abs(1/(cos(2pifH(1-1i*D)/Vs)))
Grafico
curve(A2, 0, 100, n = 100000, xlab="f [Hz]", ylab= "A2(f)", col="blue", main="Funzione di amplificazione A2", sub="Smorzamento D = 5 %", lwd="1")
Calcolo massimo
passoFrequenza = 0.001
FrequenzaMax = 100
N = FrequenzaMax/passoFrequenza
VettoreMassimo <- vector(mode = "numeric")
VetFreqA2 <- vector(mode = "numeric")
for(k in 1:N)
{
j=(k0.001)
VettoreMassimo[k]=abs(1/(cos(2pijH*(1-1i*D)/Vs)))
VetFreqA2[k]=j
}
m = max(VettoreMassimo)
#Calcolo frequenza fondamentale
ind = which.max(VettoreMassimo)
f0 = VetFreqA2[ind]
#Stampa risultati
print("Valore massimo di A2")
print(m)
print("Frequenza fondamentale f0")
print(f0)
I know it's not the most elegant way to do it, but it works!