problem by using symengine
1 view (last 30 days)
Show older comments
Hallo,
i am trying to program this code but when i try to use jacobian by A matrix i became wrone msg that error by using symengine
but it works with B matrix !!
the msg also says "unable to convert experssion into double array"
%aufgabestellung3
clear all;clc;close all;
L=[0 1 4 9 0 1 2 3]';[n,~]=size(L);
r=4; n=8; u=2;
Lsym=sym('Lsym',[n,1]);
v0=zeros(n,1); vsym=sym('vsym',[n,1]);
X0=[0 0]';
[u,~]=size(X0);
Xsym=sym('Xsym',[u,1]);
r=4;
%sto Modell
Qll=eye(n);
P=inv(Qll);
%funk Modell % Ansatz: L=[x;y]; 0=ax+b-y; X=[a b];
% A=[x ones(r,1)]; B=[X0(1,1)*eye(r) -1*eye(r)];
for i =1:r
f(i,1)=Xsym(2,1)+Xsym(1,1)*(Lsym(r+i,1)+vsym(r+i,1))-(Lsym(i,1)+vsym(i,1));
end
it=0;abr=1;
while it<10 & abr>10^-20
B=double(subs(jacobian(f,vsym),[vsym;Xsym],[v0;X0]));
% A=[x+v0(1:r,1) ones(r,1)]
A=double(subs(jacobian(f,Xsym),[vsym;Xsym],[v0;X0])); % here i become the wrong !
w0=double(subs(f,[Lsym;Xsym],[L;X0]));
w=-B*v0+w0
% Loesungsalgorithmus (Niemeier S. 178 Gl. 5.2.30)
iBQB=inv(B*inv(P)*B'); % Substitution
Q22=-inv(A'*iBQB*A);
Q12=-iBQB*A*Q22;
Q21=Q12';
Q11=iBQB*(eye(r)-A*Q21);
% Gleichung 5.2.31
k=-Q11*w;
xd=-Q21*w;
Xd=X0+xd
Qll=inv(P);
v=Qll*B'*k;
Ld=L+v;
wd=zeros(r,1)
wd=double(subs(f,[vsym;Xsym],[v;Xd]));
abr=max(abs(wd))
it=it+1
X0=Xd
end
2 Comments
Walter Roberson
on 14 Sep 2020
Your code is assuming that the jacobian of f with respect to Xsym gets rid of all Lsym variables, but it does not. You have sub-expressions that are Lsym times something involving Xsym variables, so the Lsym remain in the jacobian.
Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!