System Modeler in WLJS
circuit`sim = SystemModelSimulate["IntroductoryExamples.ComponentBased.ElectricCircuit", 10];
SystemModelPlot[circuit`sim, {"inductor1.i", "capacitor1.v"}, PlotRange -> All, PlotLegends -> {"inductor current (A)", "capacitor voltage (V)"}]
Parameter sweep
circuit`sweep = Table[SystemModelSimulate["IntroductoryExamples.ComponentBased.ElectricCircuit", 10, <|"ParameterValues" -> {"resistor1.R" -> r}|>], {r, {1, 10, 100}}];
Plot[Evaluate[#["capacitor1.v"][t] & /@ circuit`sweep], {t, 0, 10}, PlotRange -> All, PlotLegends -> {"R1 = 1 Ω", "R1 = 10 Ω", "R1 = 100 Ω"}, AxesLabel -> {"t (s)", "capacitor voltage (V)"}]
A mechanical example from the Modelica Standard Library
first`sim = SystemModelSimulate["Modelica.Mechanics.Rotational.Examples.First", 1];
SystemModelPlot[first`sim, {"inertia1.w", "inertia2.w", "inertia3.w"}, PlotRange -> All, PlotLegends -> {"inertia1.w", "inertia2.w", "inertia3.w"}]
"Speed of inertia1 at t = 1 s: " <> ToString[NumberForm[first`sim["inertia1.w", 1], 4]] <> " rad/s"
NotebookSave[EvaluationNotebook[], FileNameJoin[{$HomeDirectory, "Documents", "Claude", "portfolio-build", "showcase-notebooks", "system-modeler-in-wljs.wln"}]];