#--------------------------------------- # potenza in regime sinusoidale # # GdA maggio 2011 #--------------------------------------- nu = 60 # Hertz (tanto per metterci un valore) T = 1/nu # periodo omega = 2*pi*nu # pulsazione V0 = 1. # tensione unitaria t = seq(0,3*T, len=300) while (1) { # loop infinito, finche' nusunut > 0 cat ("\n >> dai modulo di Z (in Ohm; niente per terminare) e fase (gradi)\n") z.pol = scan("",nmax=2) if (length(z.pol) < 2) break Z = z.pol[1]*cos(z.pol[2]*pi/180) + 1i*z.pol[1]*sin(z.pol[2]*pi/180) v = V0*exp(1i*omega*t) i = v/Z p = v*i V = Re(v) I = Re(i) P = V*I P.mean = sum(P[t<=T])*(t[2]-t[1])/T * (length(t)-1)/length(t) # valore approsimativo P.mean.th = (V0^2/2)/abs(Z) *Re(Z)/abs(Z) cat( sprintf("Potenza media %.2e W\n", P.mean.th) ) layout(matrix(c(1:3),c(3,1))) plot(t, V, ty='l', xlab='t(s)', ylab='V', main='tensione [60Hz]') titolo = sprintf("Corrente, Z = %.0f Ohm, %.0f gradi [%.1f + %.1fj Ohm]", z.pol[1], z.pol[2], Re(Z), Im(Z)) plot(t, I, ty='l', xlab='t(s)', ylab='I (A)', col='blue', main=titolo) titolo = sprintf("Potenza, Z = %.0f Ohm, %.0f gradi [%.1f + %.1fj Ohm]", z.pol[1], z.pol[2], Re(Z), Im(Z)) plot(t, P, ty='l', xlab='t(s)', ylab='P (W)', col='red', main=titolo) abline(c(0,0), lty='dashed') abline(P.mean, 0, col='red') layout(1) }