Why is lscov giving me a very different solution to a simple system with an analytical solution?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am making a simple comparison for the solution of a linear system that I'd normally just solve by hand to the solution given by lscov. I thought this would be very quick and straightforward but I'm getting completely different results and I can't seem to find why. I'm sure it's something silly but I'm not finding it. I'm using MATLAB 2016a. Many thanks in advance!!!
Here is the code:
vel is a 212400 x 4 matrix.
% Least-square solution
bangle=25;
c=+1;
a=1./(2*sind(bangle));
b=1./(4*cosd(bangle));
d=a./sqrt(2);
zr=zeros(size(a));
t_matrix = [c.*a -c.*a zr zr;...
zr zr -c.*a c.*a;...
b b b b;...
d d -d -d];
[vel_sol] = lscov(t_matrix,vel'); % in vel_sol the first row is X, than Y, Z and e
% Traditional method
b1 = vel(:,1);
b2 = vel(:,2);
b3 = vel(:,3);
b4 = vel(:,4);
X_traditional = (b1 - b2)./(2*sind(bangle));
Y_traditional = (b4 - b3)./(2*sind(bangle));
Z_traditional = (b1 + b2 + b3 + b4)./(4*cosd(bangle));
e_traditional = (b1 + b2 - b3 - b4)./(2*sqrt(2)*sind(bangle));
% Plot both
plot(X_traditional)
hold on
plot(vel_sol(1,:))
2 Kommentare
Bjorn Gustavsson
am 12 Aug. 2022
Because your transfer-matrix doesn't correspond to the "traditional method" relation between vel and your X Y Z and e. Have you checked that it does what it should with simple test-cases that you can interpret manually?
Antworten (1)
John D'Errico
am 12 Aug. 2022
Bearbeitet: John D'Errico
am 12 Aug. 2022
This is not the fault of lscov. As you have written it, t_matrix is quite well conditioned. There is only one solution to the problem you have formulated. lscov will find it, or you could have used any other tool. Therfore the problem must lie in your claims. Should the two solutions be the same? We can verify that.
First, a is a scalar. So zr is just 0. I'll leave a and b in a symbolic form so it is easier to trace through the equations, easier to read. Only at the end will I replace a and b
zr = 0;
c = 1;
syms a b
d = a/sqrt(sym(2));
t_matrix = [c.*a -c.*a zr zr;...
zr zr -c.*a c.*a;...
b b b b;...
d d -d -d]
Now, what you wrote, as the "traditional solution" was just
syms b1 b2 b3 b4
t_matrix*[b1;b2;b3;b4]
All you did was to multiply t_matrix by the vector [b1;b2;b3;b4].
We can now substitute in a and b. I'll still leave bangle as symbolic though.
syms bangle
subs(t_matrix*[b1;b2;b3;b4],[a,b],[1/(2*sind(bangle)),1/(4*cosd(bangle))])
Your "traditional solution" was nothing of the sort. You never solved ANY system of equations here. But then you used lscov, which DOES solve a linear system of equations. So of course you got a different esult. What should you expect?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!