Using fsolve to find x1 and x2

How to use two different ways to find x1 and x2 using either c-script or creating a mask.

fsol_finding_x1_x2.plecs (11.2 KB)

1 Like

Hello and thank you for your question. PLECS Standalone cannot evaluate Octave functions (like fsolve) during runtime, but rather only during initialization. Further, the C-Script block cannot use a MATLAB function. In order to use the MATLAB’s fsolve function here, you will need to use Simulink and PLECS Blockset. If you are PLECS student user, you have access to PLECS Blockset in addition to PLECS Standalone. Thanks!

The problem stated in your example model looks a bit strange: Why would you want to modify the starting point x0 for the call to fsolve during the simulation?

I suspect that you rather want to solve a parameterised set of equations like the following

Cx1 - x2 - exp(-x1) = 0-x1 + Cx2 - exp(-x2) = 0with C being a parameter that you wish to vary throughout the simulation.

This can be done using the Algebraic Constraint block introduced in PLECS 4.1. Please see the attached model. The two Function blocks implement the left hand sides of the two equations with u(1) and u(2) representing x1 and x2 and u(3) representing the parameter C. The Algebraic Constraint block finds x1 and x2 such that the Function blocks will output 0.

AlgebraicConstraint.plecs (5.14 KB)