Skip to content

Commit 2af87a0

Browse files
committed
better centering schematic. Adding bilinear
1 parent 2c53817 commit 2af87a0

3 files changed

Lines changed: 24 additions & 34 deletions

File tree

filterAnalyzer/modules/main.js

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,18 @@ function updateGraph(el, freq, mag) {
189189

190190
function TransformResults(props) {
191191

192-
// Old latex
193-
// <div className="row">
194-
// The answer you provided is: ${MyComponentOLD(props.deleteMeLatex)}
195-
// </div>
196192

197193
var z = html`
198194
199-
<div className="row my-2 py-1">
200-
<div className="col shadow-sm rounded bg-white me-2">
195+
<div className="row my-2 py-1 shadow-sm rounded bg-white me-2">
196+
<div className="col">
201197
<div className="row text-center">
202-
<h3>Laplace Transform</h3>
198+
<h3>${props.title} Transform</h3>
203199
</div>
204200
<div className="row text-center fs-3 py-2">
205201
${MyComponent(props.latex)}
206202
</div>
207203
</div>
208-
<div className="col shadow-sm rounded bg-white ms-2">
209-
<div className="row text-center">
210-
<h3>Bilinear Transform</h3>
211-
</div>
212-
</div>
213204
</div>
214205
`
215206
// console.log(z);
@@ -244,18 +235,6 @@ function selectUnits(name) {
244235
}
245236

246237

247-
248-
// function createMarkup(latex) {
249-
// return {
250-
// __html: katex.renderToString(`${latex}`, {
251-
// throwOnError: false
252-
// })
253-
// };
254-
// }
255-
256-
// function MyComponentOLD(latex) {
257-
// return html`<div dangerouslySetInnerHTML=${createMarkup(latex)} />`
258-
// }
259238
function MyComponent(latex) {
260239
// console.log('latex!', latex)
261240
var z = `<math>
@@ -378,7 +357,7 @@ function centerSchematic (schem) {
378357
// var wrapperComputedStyle = window.getComputedStyle(canvasHolder, null);
379358
var wrapperWidth = canvasHolder.clientWidth - 26;
380359
var wrapperHeight = canvasHolder.offsetHeight;
381-
var centerX = (wrapperWidth-16) / 2;
360+
var centerX = (wrapperWidth-64) / 2;
382361
var centerY = (wrapperHeight-128) / 2;
383362
console.log(centerX,centerY);
384363
var minX=0;
@@ -429,7 +408,7 @@ class Game extends React.Component {
429408
}
430409
],
431410
latex: null,
432-
deleteMeLatex: null,
411+
bilinearMathML: null,
433412
elOnSchematic: [],
434413
schematicReadiness : {
435414
vout: false,
@@ -517,11 +496,11 @@ class Game extends React.Component {
517496
// console.log("Inside handleCanvasChange");
518497
var current = JSON.parse(JSON.stringify(this.state.history[this.state.history.length - 1]));
519498

520-
var latexResult, deleteMeLatex;
499+
var latexResult, deleteMeLatex, bilinearMathML;
521500
var newElementMap;
522501
var elements = current.elements;
523502
var schematicReadiness;
524-
[schematicReadiness, latexResult, newElementMap, deleteMeLatex, this.resString] = calculateMNA(canvasState);
503+
[schematicReadiness, latexResult, newElementMap, deleteMeLatex, this.resString, bilinearMathML] = calculateMNA(canvasState);
525504
this.state.elOnSchematic = newElementMap;
526505

527506
var schematicState = [];
@@ -595,14 +574,14 @@ class Game extends React.Component {
595574
if (this.preventNewState) {
596575
this.setState({
597576
latex: latexResult,
598-
deleteMeLatex: deleteMeLatex,
577+
bilinearMathML: bilinearMathML,
599578
schematicReadiness: schematicReadiness
600579
}, this.calculateTF);
601580
} else {
602581
this.setState({
603582
history: this.state.history.concat([current]),
604583
latex: latexResult,
605-
deleteMeLatex: deleteMeLatex,
584+
bilinearMathML: bilinearMathML,
606585
schematicReadiness: schematicReadiness
607586
}, this.calculateTF);
608587
}
@@ -716,13 +695,14 @@ class Game extends React.Component {
716695
<${listElements} e=${current.elements} key="valueList" onChange=${(e, i) => this.handleElChange(e, i)} unitChange=${(e, i) => this.handleUnitChange(e, i)}/>
717696
</div>
718697
</div>
719-
<${TransformResults} name="World" key="TransformResults" latex=${this.state.latex} deleteMeLatex=${this.state.deleteMeLatex} />
698+
<${TransformResults} name="World" key="TransformResults" title="Laplace" latex=${this.state.latex} bilinearMathML=${this.state.bilinearMathML} />
720699
<div className="row shadow-sm rounded bg-white my-2 py-1" id="schematic">
721700
<div className="col">
722701
<${FreqResponse} key="FreqResponse"/>
723702
<${FreqResponseControllers} key="FreqResponseControllers" fminValue=${current.fmin.value} fminUnit=${current.fmin.unit} fmaxValue=${current.fmax.value} fmaxUnit=${current.fmax.unit} onChange=${(e, i) => this.handleElChange(e, i)} unitChange=${(e, i) => this.handleUnitChange(e, i)} />
724703
</div>
725704
</div>
705+
<${TransformResults} name="World" key="TransformResultsBilin" title="Bilinear" latex=${this.state.bilinearMathML}/>
726706
<${Comments} key='comments' />
727707
</div>
728708
</div>

filterAnalyzer/modules/mna.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export function calculateMNA(canvasState) {
279279
Algebrite.eval("mna_vo_vi = simplify(inv_mna[" + (voutNode + 1) + "][" + (mnaMatrix.length-numOpAmps) + "])")
280280
Algebrite.eval("bilinear = subst((2/T)*(Z-1)/(Z+1),S,mna_vo_vi)")
281281
// latexResult = Algebrite.run("printlatex(mna_vo_vi)");
282-
console.log(Algebrite.eval("bilinear").toString());
282+
// console.log(Algebrite.eval("bilinear").toString());
283283
var resString, resMathML;
284284
[resString, resMathML] = simplify_algebra(Algebrite.eval("mna_vo_vi").toString());
285285
schematicReadiness.solvable = true;
@@ -288,6 +288,15 @@ export function calculateMNA(canvasState) {
288288
resMathML = "<mtext>Schematic currently invalid</mtext>"
289289
}
290290

291+
var discard, bilinearMathML;
292+
try {
293+
[discard, bilinearMathML] = simplify_algebra(Algebrite.eval("bilinear").toString());
294+
} catch {
295+
bilinearMathML = "<mtext>Having trouble calculating bilinear transform</mtext>"
296+
}
297+
298+
299+
291300

292301

293302

@@ -304,13 +313,14 @@ export function calculateMNA(canvasState) {
304313

305314
} else {
306315
resMathML = "<mtext>Schematic currently invalid</mtext>"
316+
bilinearMathML = "<mtext>Schematic currently invalid</mtext>"
307317
schematicReadiness.solvable = false;
308318
}
309319

310320
// console.log('bp2', resString)
311321

312322

313-
return [schematicReadiness, resMathML, allElements, latexResult, resString];
323+
return [schematicReadiness, resMathML, allElements, latexResult, resString, bilinearMathML];
314324

315325

316326

filterAnalyzer/modules/simplify_algebra.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '../js/expression/polynomial-roots-finding.js';
66
import '../js/expression/toMathML.js';
77

88
export default function simplify_algebra(expr) {
9-
var z = expr.replace(/([a-zA-RT-Z]+)([0-9]*)/g,"$1_$2"); //Swap R0 for R_0 so this new library can consume it //not S
9+
var z = expr.replace(/([a-zA-RU-Y]+)([0-9]*)/g,"$1_$2"); //Swap R0 for R_0 so this new library can consume it //not S
1010
// console.log("i'm here!", expr, z);
1111
var matrix = ExpressionParser.parse(z);
1212
var t = matrix.toString();

0 commit comments

Comments
 (0)