unexpected object of type 'RootOf'

9 views (last 30 days)
Mert sargin
Mert sargin on 18 Jul 2022
Edited: Mert sargin on 19 Jul 2022
Hi everyone, I am trying to perform a simple curvefitting, but Matlab keeps throwing this error message at me. Does anyone know whats the issue?
It is weird that I only encounter this problem when I try to work with the function Aufheiz6Var, but I get no issues when working with Aufheiz4var and Aufheiz2Var, they are almost exactly the same functions but just different equations.
Error using symengine
Code generation failed due to unexpected object of type
'RootOf'.
res1 = mupadmex('symobj::generateMATLAB',r.s,ano,spa,splitIt);
r = mup2mat(c{1},true,sparseMat,false);
body = mup2matcell(funs, opts.Sparse);
gs=matlabFunction(ilaplace(Zges*rect))
Error in 1515 (line 55)
bx=@(start)Aufheiz6var(Res(i-2),Res(i-1),Res(i),Cap(i-2),Cap(i-1),start,Zth,time(i,:),aufheizdauer);
Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});
if i==2
Zth=temp(i,:)/PHI;
Res(i)=Zth(aufheizdauer)-Res(i-1);
bx=@(start)Aufheiz4var(Res(i-1),Res(i),Cap(i-1),start,Zth,time(i,:),aufheizdauer);
AufheizParameter=fminsearch(bx,start);
Cap(i)=AufheizParameter;
end
if i==3
Zth=temp(i,:)/PHI;
Res(i)=Zth(aufheizdauer)-Res(i-1)-Res(i-2);
bx=@(start)Aufheiz6var(Res(i-2),Res(i-1),Res(i),Cap(i-2),Cap(i-1),start,Zth,time(i,:),aufheizdauer);
AufheizParameter=fminsearch(bx,start);
Cap(i)=AufheizParameter;
end
function A=Aufheiz6var(R1,R2,R3,C1,C2,C3,Zth,xm,aufheizdauer)
syms s
Z3=R3/(R3*C3*s+1);
Z2=(R2+Z3)/((R2+Z3)*C2*s+1);
Z1=R1+Z2;
Zges=1/(s*C1+1/Z1);
rect=(1-exp(-s*aufheizdauer))/s;
gs=matlabFunction(ilaplace(Zges*rect))
A=sum((gs(xm)-Zth).^2);
clf;
plot(xm,Zth,'b');
hold on;
plot(xm,gs(xm),'r');
drawnow
end
function A=Aufheiz4var(R1,R2,C1,C2,Zth,xm,aufheizdauer)
syms s
Z2=R2/(R2*C2*s+1);
Z1=R1+Z2;
Zges=1/(s*C1+1/Z1);
rect=(1-exp(-s*aufheizdauer))/s;
gs=matlabFunction(ilaplace(Zges*rect));
A=sum((gs(xm)-Zth).^2);
clf;
plot(xm,Zth,'b');
hold on;
plot(xm,gs(xm),'r');
drawnow
end

Accepted Answer

Paul
Paul on 18 Jul 2022
I'm going to speculate that the denominator of Zges*rect in Aufheiz6Var is of too high of an order for the Symbolic Math Toolbox to be able to factor exactly as it would need to do for ilaplace(). Unless you need closed-form expressions, consider not using the SMT at all, and instead use the Control Systems Toolbox to generated the time responses.
  7 Comments
Paul
Paul on 19 Jul 2022
From what I understand, you must have a time vector of 1 x 800001 that pairs up with the elements of Zth. Let's call this time vector Tth. Is Tth equally spaced?
If it is, then you can do
y = impulse(YCst,Tth);
to get the values of y at the corresponding value of Tth, assuming the spacing of the elements of Tth is small enough relative to the dynamics of Ycst.
If Tth is not equally spaced, you can try to compute the impulse response of Ycst and then interpolate it to values of Tth, as shown below allowing Matlab to select the time vector for the impulse response (or you can specify yourself) and using the default linear interpolation (which you can also change).
[y,t] = impulse(Ycst,Tth(end));
y = interp1(t,y,Tth);
I still don't understand why aufheizdauer would get into the call to impulse, unless aufheizdauer = TTh(end).
If you want to go down the symbolic path using matlabFunction, you can try to use vpa to get past the rootOf issue
syms s t
y(t) = ilaplace(1/(s^5 + 2*s^4 + 3*s^3 + 4*s^2 + s + 1))
y(t) = 
y(t) = vpa(y(t))
y(t) = 
vpa(y(t),5) % for visibility
ans = 
matlabFunction(y(t))
ans = function_handle with value:
@(t)exp(t.*-1.597626686280057).*8.974810715078028e-2-exp(t.*-3.197963122886144e-2).*cos(t.*5.548185101647158e-1).*2.633024724275729e-1+exp(t.*-3.197963122886144e-2).*sin(t.*5.548185101647158e-1).*5.749882554495332e-1+exp(t.*-1.6920702563111e-1).*cos(t.*1.413518888969003).*1.735543652767926e-1-exp(t.*-1.6920702563111e-1).*sin(t.*1.413518888969003).*1.09431756071144e-1
Mert sargin
Mert sargin on 19 Jul 2022
Edited: Mert sargin on 19 Jul 2022
I cant thank you enough. You are such a blessing. Its working now.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!