Questo codice ci permette di calcolare la tensione, la corrente e le varie resistenze nel circuito in parallelo e nel circuito in serie.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Circuiti Serie e Parallelo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<h1>Calcolo resistenze in serie e parallelo</h1>
<label for="v">V</label><br>
<input type="text" id="v"><br>
<label for="i">I</label><br>
<input type="text" id="i"><br>
<label for="r1">R1</label><br>
<input type="text" id="r1"><br>
<label for="r2">R2</label><br>
<input type="text" id="r2"><br>
<label for="r3">R3</label><br>
<input type="text" id="r3"><br><br>
<button type="button" class="btn btn-secondary" onclick="calcoloReqSerie()">Calcolo Req Serie</button><br><br>
<button type="button" class="btn btn-secondary" onclick="calcoloV()">Calcolo V1,V2,V3</button><br><br>
<button type="button" class="btn btn-secondary" onclick="calcoloReqParallelo()">Calcolo Req Parallelo</button><br><br>
<button type="button" class="btn btn-secondary" onclick="calcoloI()">Calcolo I1,I2,I3</button>
<p id="out"></p>
</body>
<script>
function calcoloReqSerie(){
let R1, R2, R3;
R1=parseFloat(document.getElementById("r1").value);
R2=parseFloat(document.getElementById("r2").value);
R3=parseFloat(document.getElementById("r3").value);
ReqSerie=calcolaResistenzaEquivalente(R1, R2, R3);
document.getElementById("out").innerHTML+= "La resistenza equivalente in serie è: " + ReqSerie + "<br>"
}
function calcolaResistenzaEquivalente(A, B, C){
return A+B+C;
}
function calcoloV(){
let R1, R2, R3, I;
R1=parseFloat(document.getElementById("r1").value);
R2=parseFloat(document.getElementById("r2").value);
R3=parseFloat(document.getElementById("r3").value);
I=parseFloat(document.getElementById("i").value);
V1=calcoliParziali(R1, I)
V2=calcoliParziali(R2, I)
V3=calcoliParziali(R3, I)
document.getElementById("out").innerHTML+= "V1 = " + V1 + "<br>"
document.getElementById("out").innerHTML+= "V2 = " + V2 + "<br>"
document.getElementById("out").innerHTML+= "V3 = " + V3 + "<br><br>"
}
function calcoliParziali(A, B){
return A*B
}
function calcoloReqParallelo(){
let R1, R2, R3;
R1=parseFloat(document.getElementById("r1").value);
R2=parseFloat(document.getElementById("r2").value);
R3=parseFloat(document.getElementById("r3").value);
ReqParallelo=calcoloParallelo(R1, R2, R3);
document.getElementById("out").innerHTML+= "La resistenza equivalente in parallelo è: " + ReqParallelo + "<br>"
}
function calcoloParallelo(A, B, C){
return (1/A+1/B+1/C);
}
function calcoloI(){
let R1, R2, R3, V;
R1=parseFloat(document.getElementById("r1").value);
R2=parseFloat(document.getElementById("r2").value);
R3=parseFloat(document.getElementById("r3").value);
V=parseFloat(document.getElementById("v").value);
I1=calcoloCorrenti(R1, V)
I2=calcoloCorrenti(R2, V)
I3=calcoloCorrenti(R3, V)
document.getElementById("out").innerHTML+= "I1 = " + I1 + "<br>"
document.getElementById("out").innerHTML+= "I2 = " + I2 + "<br>"
document.getElementById("out").innerHTML+= "I3 = " + I3 + "<br>"
}
function calcoloCorrenti(A, B){
return A/B
}
</script>
</html>