solve a non linear equation in simscape

8 vues (au cours des 30 derniers jours)
Derek Lastiwka
Derek Lastiwka le 29 Jan 2020
Modifié(e) : Aayush Agrawal le 12 Fév 2021
I would need to solve a non linear equations to determine a constant for use in the equations portion of a custom simscape block. I have tried using the matlab fzero command but simscape does not like the anonymous function. I have also writtent a custome simscape fucntion to solve the non linear equation but simscape does not like th while loop. Is there a way to solve a nonlinear equation in simscape?

Réponses (1)

Aayush Agrawal
Aayush Agrawal le 12 Fév 2021
Modifié(e) : Aayush Agrawal le 12 Fév 2021
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
%Other sections
variables
x = 0; %An initial guess to the root of the non-linear equation, where x is the unknown variable in the non-linear equation.
end
equations
%Other equations which may or may not use 'x'
der(x) == {0, '1/s'}; %Set the derivative to zero so that the value of the root does not change during the simulation
end
equations(Initial = true)
%Add the non-linear equations involving x here.
end
end
Thanks,
Aayush

Catégories

En savoir plus sur Model Preparation dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by