Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Thomas Kraus
Thomas Kraus am 30 Mär. 2022
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).

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ishu
Ishu am 5 Feb. 2024
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:

Kategorien

Mehr zu Applications finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by