I'm trying to create a custom interface, where I input equivalent electrical resistances which were previously measured, so I can solve a system of 8 non linear equations using FindRoot to get the actual resistances values I want (for two wheatstone bridges). My aim is to have an interface where I can easily input these measurements and obtain the values I want inside boxes, after the click of a button. I started by using GUIkit, but then learned that it was deprecated and went on using CreateDialog, and got this until now:
CreateDialog[
Column[{Row[{TextCell["Equivalent Resistance 1: "],
InputField[Dynamic[req1], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance 2: "],
InputField[Dynamic[req2], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance 3: "],
InputField[Dynamic[req3], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance 4: "],
InputField[Dynamic[req4], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance A: "],
InputField[Dynamic[reqa], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance B: "],
InputField[Dynamic[reqb], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance C: "],
InputField[Dynamic[reqc], Number, FieldSize -> {5, 1}]}],
Row[{TextCell["Equivalent Resistance D: "],
InputField[Dynamic[reqd], Number, FieldSize -> {5, 1}]}],
Button[
"Compute", {Clear[req1, req2, req3, req4, reqa, reqb, reqc,
reqd]}]
}],
WindowTitle -> "Wheatstone Bridges"
];
It doesn't do anything useful yet, but my question is: Are there any other tools I would be better off with, to do this rather than using DialogBoxes? I feel that using this method is giving me more problems than when I was using GUIkit, which felt quite intuitive. Do you recommend other softwares, like MatLab, to do these kinds of custom interfaces? Thank you for your insight.
UPDATE:
@m_Goldberg, Thank you very much for the time spent helping me! After reading the documentation I came up with the following, functional, program:
CreateDialog[
DynamicModule[{inputs, outputs, req1, req2, req3, req4, reqa, reqb,
reqc, reqd, r1, r2, r3, r4, ra, rb, rc, rd, sol, sol1, sol2, sol3,
sol4, sola, solb, solc, sold, eq1, eq2, eq3, eq4, eqa, eqb, eqc,
eqd, init1 = 1, init2 = 1, init3 = 1, init4 = 1, inita = 1,
initb = 1, initc = 1, initd = 1, unit},
unit = Row["ola"];
inputs =
MapThread[
Row[{"Equivalent MS", #1, ": ",
InputField[Dynamic@#2, Number,
FieldSize -> {5, 1}]}] &, {{"1", "2", "3", "4", "A", "B",
"C", "D"}, {req1, req2, req3, req4, reqa, reqb, reqc, reqd}}];
outputs =
MapThread[
Row[{" MS", #1, ": ",
Dynamic@
Pane[Dynamic@#2, 100, BaseStyle -> {Background -> White},
FrameMargins -> 4]}] &, {{"1", "2", "3", "4", "A", "B", "C",
"D"}, {sol1, sol2, sol3, sol4, sola, solb, solc, sold}}
];
req1 =
req2 = req3 =
req4 = reqa =
reqb = reqc =
reqd = sol1 =
sol2 = sol3 = sol4 = sola = solb = solc = sold = 0;
Column[{Row[{Column[Join[inputs, {}]
],
Column[outputs]
}],
Row[{Button[
"Reset", {req1 =
req2 = req3 =
req4 = reqa =
reqb = reqc =
reqd = sol1 =
sol2 = sol3 = sol4 = sola = solb = solc = sold = 0,
init1 = 1, init2 = 1, init3 = 1, init4 = 1, inita = 1,
initb = 1, initc = 1, initd = 1}],
Button["Compute",
If[
req1 == 0 || req2 == 0 || req3 == 0 || req4 == 0 ||
reqa == 0 || reqb == 0 || reqc == 0 ||
reqd == 0, {sol1 =
sol2 = sol3 = sol4 = sola = solb = solc = sold = 0}, {
eq1 = (r1*(((r3 +
r4)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r3 +
r4 + (((ra + rb)*(rc + rd))/(ra + rb + rc +
rd))) +
r2))/(r1 + (((r3 +
r4)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r3 +
r4 + ((ra + rb)*(rc + rd))/(ra + rb + rc + rd))) +
r2) == req1;
eq2 = (r2*(((r3 +
r4)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r3 +
r4 + (((ra + rb)*(rc + rd))/(ra + rb + rc +
rd))) +
r1))/(r2 + (((r3 +
r4)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r3 +
r4 + ((ra + rb)*(rc + rd))/(ra + rb + rc + rd))) +
r1) == req2;
eq3 = (r3*(((r1 +
r2)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r1 +
r2 + (((ra + rb)*(rc + rd))/(ra + rb + rc +
rd))) +
r4))/(r3 + (((r1 +
r2)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r1 +
r2 + ((ra + rb)*(rc + rd))/(ra + rb + rc + rd))) +
r4) == req3;
eq4 = (r4*(((r1 +
r2)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r1 +
r2 + (((ra + rb)*(rc + rd))/(ra + rb + rc +
rd))) +
r3))/(r4 + (((r1 +
r2)*(((ra + rb)*(rc + rd))/(ra + rb + rc +
rd)))/(r1 +
r2 + ((ra + rb)*(rc + rd))/(ra + rb + rc + rd))) +
r3) == req4;
eqa = (ra*(((rc +
rd)*(((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4)))/(rc +
rd + (((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4))) +
rb))/(ra + (((rc +
rd)*(((r1 + r2)*(r3 + r4))/(ra + rb + rc +
rd)))/(rc +
rd + ((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 + r4))) +
rb) == reqa;
eqb = (rb*(((rc +
rd)*(((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4)))/(rc +
rd + (((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4))) +
ra))/(rb + (((rc +
rd)*(((r1 + r2)*(r3 + r4))/(ra + rb + rc +
rd)))/(rc +
rd + ((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 + r4))) +
ra) == reqb;
eqc = (rc*(((ra +
rb)*(((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4)))/(ra +
rb + (((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4))) +
rd))/(rc + (((ra +
rb)*(((r1 + r2)*(r3 + r4))/(ra + rb + rc +
rd)))/(ra +
rb + ((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 + r4))) +
rd) == reqc;
eqd = (rd*(((ra +
rb)*(((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4)))/(ra +
rb + (((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 +
r4))) +
rc))/(rd + (((ra +
rb)*(((r1 + r2)*(r3 + r4))/(ra + rb + rc +
rd)))/(ra +
rb + ((r1 + r2)*(r3 + r4))/(r1 + r2 + r3 + r4))) +
rc) == reqd;
sol = FindRoot[{eq1, eq2, eq3, eq4, eqa, eqb, eqc,
eqd}, {{r1, init1}, {r2, init2}, {r3, init3}, {r4,
init4}, {ra, inita}, {rb, initb}, {rc, initc}, {rd,
initd}}],
sol1 = sol[[1, 2]], sol2 = sol[[2, 2]], sol3 = sol[[3, 2]],
sol4 = sol[[4, 2]], sola = sol[[5, 2]], solb = sol[[6, 2]],
solc = sol[[7, 2]], sold = sol[[8, 2]]
}]],
Button["Init",
CreateDialog[{TextCell[
"Choose starting points (default = 1):"],
Column[{
Row[{"Init1: ",
InputField[Dynamic[init1], Number, FieldSize -> {5, 1}],
"Init2: ",
InputField[Dynamic[init2], Number, FieldSize -> {5, 1}],
"Init3: ",
InputField[Dynamic[init3], Number, FieldSize -> {5, 1}],
"Init4: ",
InputField[Dynamic[init4], Number,
FieldSize -> {5, 1}]}],
Row[{"InitA: ",
InputField[Dynamic[inita], Number, FieldSize -> {5, 1}],
"InitB: ",
InputField[Dynamic[initb], Number, FieldSize -> {5, 1}],
"InitC: ",
InputField[Dynamic[initc], Number, FieldSize -> {5, 1}],
"InitD: ",
InputField[Dynamic[initd], Number,
FieldSize -> {5, 1}]}],
Row[{DefaultButton[]}]}
]}];],
CancelButton[],
DefaultButton[DialogReturn[]]}]
}]
],
WindowTitle -> "Wheatstone Bridges (k\[CapitalOmega])"
];
It does what I initially explained in the introduction of this question. I'll read your new update to further improve the code. Once again, thank you very , very much!
CreateDialog
and have the UI in the notebook. $\endgroup$ – Edmund Aug 10 '17 at 2:27DynamicModule
orManipulate
but a dialog was suggested as it was doing what your GUIKit example was doing. This is the way to go in Mathematica, you can read related tutorials (go to Manipulate documentation and scroll down to see tutorials) to understand it better. About other software, this is off topic here/option based and unclear untill you make clear what does not work as you like. $\endgroup$ – Kuba♦ Aug 10 '17 at 6:43