Please take a minute to review and accept our Terms of Use.
Welcome to PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Using fsolve to find x1 and x2

+1 vote
67 views
How to use two different ways to find x1 and x2 using either c-script or creating a mask.
asked Jan 23 by saleh (13 points)
retagged Feb 2 by Wolfgang Hammer

2 Answers

0 votes
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!
answered Jan 24 by Kris Eberle (83 points)
0 votes

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

  • C*x1 - x2 - exp(-x1) = 0
  • -x1 + C*x2 - exp(-x2) = 0

with 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.

answered Jan 24 by Wolfgang Hammer (87 points)
...