problem by using symengine

조회 수: 7 (최근 30일)
Basem Nouh
Basem Nouh 2020년 9월 14일
편집: Walter Roberson 2020년 9월 14일
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
Walter Roberson
Walter Roberson 2020년 9월 14일
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.
Basem Nouh
Basem Nouh 2020년 9월 14일
편집: Walter Roberson 2020년 9월 14일
i edited it i have to insert L as a vector not as sympolic variable , i have no idea why
but the Prof at the uni didnt use jacobian for the Partial differentiation he inserted the both matrix A,B direct
A=[x+v0(1:r,1) ones(r,1)]
B=[X0(1,1)*eye(r) -1*eye(r)]
but i thought by jacobian or using diff its faster and safer
but there is a problem by Partial differentiation
by me B at the final is
B =
0 0 0 0 -1 0 0 0
0 0 0 0 0 -1 0 0
0 0 0 0 0 0 -1 0
0 0 0 0 0 0 0 -1
by prof B =
3.2418 0 0 0 -1.0000 0 0 0
0 3.2418 0 0 0 -1.0000 0 0
0 0 3.2418 0 0 0 -1.0000 0
0 0 0 3.2418 0 0 0 -1.0000
A =
0 1
1 1
2 1
3 1
A =
0.3838 1.0000
0.7524 1.0000
1.6843 1.0000
3.1795 1.0000
it means there is no correction happened

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by