# Matrix equation solution keep giving only structure of the array not the value

2 views (last 30 days)
new =
[ (29*y2)/5 - (7*z2)/10, 7*z2, -7*y2]
>> dif=MRA-Mprll
dif =
-0.1337 -9.7234 1.3349
>> syms y2 z2
>> eqn = new - dif ==0 ;
>> solve(eqn)
ans =
struct with fields:
y2: [0×1 sym]
z2: [0×1 sym]

John D'Errico on 8 Sep 2020
As I explained in my comment to @Vasishta Bhargava, this is a problem with 3 equations, but only 2 unknowns. It is known as an over-determined problem. As such, it likely never has an exact solution, so solve cannot solve it.
Typically, one might use a tool like a linear regression, to find y2 and z2 that will minimize the errors in the three equations at once. I'll be lazy here and just use fminsearch.
new = @(yz) [(29*yz(1))/5 - (7*yz(2))/10, 7*yz(2), -7*yz(1)];
dif = [-0.1337 -9.7234 1.3349];
obj = @(yz) norm(new(yz) - dif);
yz = fminsearch(obj,[1 1])
yz =
-0.190698528012633 -1.38904515739705
How well did it work?
[new(yz);dif]
ans =
-0.133719852295332 -9.72331610177938 1.33488969608843
-0.1337 -9.7234 1.3349
quite well in fact.
I could also have use a direct linear regression.
[A,B] = equationsToMatrix(eqn);
double(A)\double(B)
ans =
-0.190698604595212
-1.38905731126807
So the same answer, but this time it is more precise, since fminsearch uses a tolerance.

Vasishta Bhargava on 8 Sep 2020
Edited: Vasishta Bhargava on 8 Sep 2020
Type
>>ans.y2
>>ans.z2
in command window to see the values
Try this code
%if true
% code
%end
syms y2 z2
new =
[ (29*y2)/5 - (7*z2)/10, 7*z2, -7*y2];
dif =
[ -0.1337 -9.7234 1.3349];
eqn = new - dif ==0 ;
A = solve(eqn,[y2,z2]); % the correct syntax
>> A.y2
>> A.z2

Waritwong Sukprasongdee on 8 Sep 2020
for this one it still has the problem while it has 3 equations in it and when solve manually by hands it can find y and z
btw the one i post before is completely wrong because the equation itself is wrong
John D'Errico on 8 Sep 2020
@ Waritwong Sukprasongdee:
No. You found a value of y and z only because you allowed for slight inaccuracies in your data. The values in dif
dif =
-0.1337 -9.7234 1.3349
Are not truly exact, but only 4 significant dogit approximations. Solve however, does not recognize that it can ignore the small errors made in the 4th decimal digit. So it cannot exactly solve the problem.
Vasishta Bhargava on 8 Sep 2020
Some of text in comment is jumbled. Sorry for inconvenience. That text is deleted
The inet connection at my place is slow. May be thats the reason. Not mathworks cloud

R2020a

### Community Treasure Hunt

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

Start Hunting!