-
Notifications
You must be signed in to change notification settings - Fork 0
/
expt2.js
188 lines (160 loc) · 5.72 KB
/
expt2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
var count=0;
var i1,i2,i3,i12,i12,i13,i21,i22,i23;
var c1=0;
var c2=0;
var c3=0;
var dr1,dr2,dr3,dr4,dr5,dr6,dr7,dr8,dr9;
function perform1()
{
var r1,r2,r3,v1,v2,s1,s2;
var flag=0;
r1=parseFloat(document.getElementById('r1').value);
r2=parseFloat(document.getElementById('r2').value);
r3=parseFloat(document.getElementById('r3').value);
v1=parseFloat(document.getElementById('v1').value);
v2=parseFloat(document.getElementById('v2').value);
s1=parseFloat(document.getElementById('s1').value);
s2=parseFloat(document.getElementById('s2').value);
if (s1==1 && s2==1){
document.getElementById("diagram").src = "images/case1.png";
c1=1;
i11 = v1/(r1+r3);
i12 = 0;
i13 = i11;
i22 = v2;
i23 = v2*(r1/(r1+r3));
i21 = (v2-i23)*(-1);
i1 = i11 + i21;
i2 = i12 + i22;
i3 = i13 + i23;
document.f1.A1.value = i1.toPrecision(5);
document.f1.A2.value = i2.toPrecision(5);
document.f1.A3.value = i3.toPrecision(5);
document.f1.A01.value = i1.toPrecision(5);
document.f1.A02.value = i2.toPrecision(5);
document.f1.A03.value = i3.toPrecision(5);
}
else
{
alert("Please select both S1 and S2 to power for case 1.");
}
}
function perform2() {
var r1,r2,r3,v1,v2,rl1,s1,s2;
r1=parseFloat(document.getElementById('r1').value);
r2=parseFloat(document.getElementById('r2').value);
r3=parseFloat(document.getElementById('r3').value);
v1=parseFloat(document.getElementById('v1').value);
v2=parseFloat(document.getElementById('v2').value);
s1=parseFloat(document.getElementById('s1').value);
s2=parseFloat(document.getElementById('s2').value);
if (s1==1 && s2==3)
{
document.getElementById("diagram").src = "images/case2.png";
document.f1.A1.value = i11.toPrecision(5);
document.f1.A2.value = i12.toPrecision(5);
document.f1.A3.value = i13.toPrecision(5);
document.f1.A01.value = i11.toPrecision(5);
document.f1.A02.value = i12.toPrecision(5);
document.f1.A03.value = i13.toPrecision(5);
}
else
{
alert("Please select S1 to Power and S2 to Short for case 2.");
}
}
function perform3(){
var r1,r2,r3,v1,v2,rl1,s1,s2;
r1=parseFloat(document.getElementById('r1').value);
r2=parseFloat(document.getElementById('r2').value);
r3=parseFloat(document.getElementById('r3').value);
v1=parseFloat(document.getElementById('v1').value);
v2=parseFloat(document.getElementById('v2').value);
s1=parseFloat(document.getElementById('s1').value);
s2=parseFloat(document.getElementById('s2').value);
if (s1==2 && s2==1)
{
document.getElementById("diagram").src = "images/case3.png";
c3=1;
document.f1.A1.value = i21.toPrecision(5);
document.f1.A2.value = i22.toPrecision(5);
document.f1.A3.value = i23.toPrecision(5);
document.f1.A01.value = i21.toPrecision(5);
document.f1.A02.value = i22.toPrecision(5);
document.f1.A03.value = i23.toPrecision(5);
}
else
{
alert("Please select S1 to Short and S2 to Power for case 3.");
}
}
function perform4()
{
var tr= document.createElement("tr");
var td1=tr.appendChild(document.createElement("td"));
var td2=tr.appendChild(document.createElement("td"));
var td3=tr.appendChild(document.createElement("td"));
var td4=tr.appendChild(document.createElement("td"));
var td5=tr.appendChild(document.createElement("td"));
var td6=tr.appendChild(document.createElement("td"));
var td7=tr.appendChild(document.createElement("td"));
var td8=tr.appendChild(document.createElement("td"));
var td9=tr.appendChild(document.createElement("td"));
td1.innerHTML=i1.toPrecision(5)
td2.innerHTML=i2.toPrecision(5)
td3.innerHTML=i3.toPrecision(5)
td4.innerHTML=i11.toPrecision(5)
td5.innerHTML=i12.toPrecision(5)
td6.innerHTML=i13.toPrecision(5)
td7.innerHTML=i21.toPrecision(5);
td8.innerHTML=i22.toPrecision(5);
td9.innerHTML=i23.toPrecision(5);
document.getElementById("tb1").appendChild(tr);
}
function delStudent(Stud){
var s=Stud.parentNode.parentNode;
s.parentNode.removeChild(s);
}
var caseTest = 1;
function divContentChange(caseNumber){
console.log(caseNumber)
caseTest = caseNumber
// var contentDiv = document.getElementById('contentDiv')
var headerCase = document.getElementById('headerCase')
var subheaderCase = document.getElementById('subheaderCase')
if(caseNumber == 1){
headerCase.textContent = "Determination of branch currents in presence of V and I :"
subheaderCase.textContent = "Select the switch S1 and S2 to power. And then click on Simulate."
//case1
return
}
else if(caseNumber == 2){
headerCase.textContent = "Determination of branch currents in presence of V only :"
subheaderCase.textContent = "Select the switch S1 and S2 to Open. And then click on Simulate."
//case2
return
}
else if(caseNumber == 3){
document.getElementById('case3Btn').style.display = "block"
headerCase.textContent = "Determination of branch currents in presence of I only :"
subheaderCase.textContent = "Select the switch S1 to Short and S2 to power. And then click on Simulate."
return
//case3
}
}
function simulate(){
if(caseTest == 1)
perform1()
else if(caseTest == 2)
perform2()
else
perform3()
}
function picChange(circuitCon){
if(circuitCon == 2)
document.getElementById("diagram").src = "images/case3.png";
else if(circuitCon == 3)
document.getElementById("diagram").src = "images/case2.png";
else
document.getElementById("diagram").src = "images/case1.png";
}