unexpected object of type 'RootOf'
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mert sargin
am 18 Jul. 2022
Bearbeitet: Mert sargin
am 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))
bx=@(start)Aufheiz6var(Res(i-2),Res(i-1),Res(i),Cap(i-2),Cap(i-1),start,Zth,time(i,:),aufheizdauer);
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
0 Kommentare
Akzeptierte Antwort
Paul
am 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 Kommentare
Paul
am 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) = vpa(y(t))
vpa(y(t),5) % for visibility
matlabFunction(y(t))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!