Solve 1D equation in simulink

2 ビュー (過去 30 日間)
gdz
gdz 2023 年 1 月 28 日
コメント済み: Paul 2023 年 1 月 29 日
Hi,
I am managed to solve the 1D equation using a Matlab function using vpasolve function with syms, but now I would like to solve it in Simulink. I realized that one way is to use call it with extrinsic function after calling MATLAB function in Simulink but it will slow down my program.
https://www.mathworks.com/matlabcentral/answers/490038-function-syms-not-supported-for-code-generation#answer_419751extrinsic function.
I would like to know if there are other way that I could solve the equation (quadratic, exponential equation) in Simulink without slowing down my program.
Thank you.

採用された回答

Paul
Paul 2023 年 1 月 29 日
編集済み: Paul 2023 年 1 月 29 日
Hi gdz,
Assuming vpasolve needed because a closed form solution can't be found ....
Can always try using an Algebraic Constraint block to solve the equation. However, this block will introduce and algebraic loop into the model, which potentially comes with other issues.
Or, use a Matlab Function block and from there call fsolve or fzero. I think that should doable.
  2 件のコメント
gdz
gdz 2023 年 1 月 29 日
編集済み: gdz 2023 年 1 月 29 日
use a Matlab Function block and from there call fsolve or fzero. I think that should doable.
I have replaced the syms to fsolve. It does not work :(
Same as syms, Matlab reported that
Function 'fsolve' not supported for code generation.
Paul
Paul 2023 年 1 月 29 日
It sure seems like fsolve (Extended Capabilities) could be made to work as it is eligible for code generation. Though there are lots of notes that may be applicable to your problem, which you haven't shown.
fzero maybe be easier.
I implemented the following in a Matab Function block to find the root of the equation
f(x) = x^3 - t
and it worked fine
function y = fcn(t)
f = @(x) x^3 - t;
y = fzero(f,1);
end
I was pleasantly suprised that the function handle didn't cause any problems.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by