Hi Derek,
Note that the Simscape equations in a custom Simscape block only support a few MATLAB functions which are listed in the documentation for the Simscape equations.
You can try the following two workarounds for resolving this issue:
- You can add a model callback function (Initialization/PreLoad/PostLoad) which solves the non linear equation you have using the 'fzero' function. You can then assign the solution to a variable which can then be assigned to a runtime parameter of your custom Simscape block. The Simscape parameter can be used in the equations section. You can refer to the help documentation for "model callbacks" to learn how to add a model callback function.
- If you are using R2019b or newer version of Simulink and Simscape, you can also use initial equations in the Simscape language. Initial equations in Simscape lets you specify additional equations that are executed during model initialization only. You can obtain the solution for the non-linear equation through the initial equations and use the solution with other equations. However, there might be some limitations to the equations that can be solved. Your code for the custom Simscape block might look like this
component CustomSimscapeBlock
variables
x = 0;
end
equations
der(x) == {0, '1/s'};
end
equations(Initial = true)
end
end
Thanks,
Aayush