How can i get a symbolic equation to a matlabFunction handle without the RootOf Problem

3 ビュー (過去 30 日間)
Thomas Kraus
Thomas Kraus 2022 年 3 月 29 日
回答済み: Ishu 2024 年 2 月 5 日
I have created a symbolic equation out of state space. Now I want to get the equation out of the function by function handle. I tried to get it with matlabFunction to a function handle, but i get the failure RootOf in the Command Window. What could be the problem. For the Function Gjw in Frequeny area there is no problem. The Failure comes only at hEq.ht in time area.
Gs = simplify(C*(s*eye(size(A)) - A)^(-1)*B + D);
Gjw = subs(Gs,s,1i*w);
Hs = Gs*1/s*Amp;
ht = ilaplace(Hs);
hEq.Gjw = matlabFunction(Gjw,'vars',{w,Ta,J,K1,K2,VP,KCDC,Ch,Ak,Kp,Amp,flagmV});
hEq.ht = matlabFunction(ht,'vars',{t,Ta,J,K1,K2,VP,KCDC,Ch,Ak,Kp,Amp,flagmV});
Could you imagine what could be the failure?
  6 件のコメント
Torsten
Torsten 2022 年 3 月 29 日
And what is z ?
Thomas Kraus
Thomas Kraus 2022 年 3 月 30 日
I don't know where the z is come from. It is not from my function description. It is included as soon as I use vpa(ht).

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

回答 (1 件)

Ishu
Ishu 2024 年 2 月 5 日
Hi Thomas,
If you check your "ht" value then it contains the expression of root. As "matlabFunction" is not able to resolve symbolic expressions containing root expressions that's why you are getting "RootOf" error while calculating "hEq.ht". So firstly you have to resolve these root expressions by simplifying expressions only then you can apply "matlabFunction" to solve further. To simplify these expressions you can try below methods:
  1. Try simplifying the expression using "simplify" function.
  2. As the expression contains roots so you can try to solve this expression explicitly using "solve" function.
  3. If the roots cannot be represented explicitly, you might consider using a numeric approximation for the roots using "vpasolve" function. This approach, however, will limit the usage of the function handle to numeric inputs only.
  4. If the expreesion contains variables that you want to replace only with specific values then to make it more simpler you can use "subs" function to substitute the values and then try to use "matlabFunction".
Below are some MathWorks documentations that you can refer:

カテゴリ

Help Center および File ExchangeManage Products についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by