MATLAB: Matlab ‘solve’ question

MATLABsolve

please tell why ans of code1 different from ans of code2
thank you.
%matlab code1
syms a b c d e f g
f1=c==8000;
f2=b==30;
f3=a==60;
f4=d==400;
f5=e==3000;
f6=f==20;
f7='(b+a+g)*f-c+d+e=0';
[b,a,c,d,e,f,g]=solve(f1,f2,f3,f4,f5,f6,f7);%this part different from code2
[a,b,c,g,d,e,f]
%end

ans =
[ 30, 8000, 60, 140, 400, 3000, 20]
%matlab code2
syms a b c d e f g
f1=a==8000;
f2=b==30;
f3=c==60;
f4=d==400;
f5=e==3000;
f6=f==20;
f7='(b+c+g)*f-a+d+e=0';
[a,b,c,d,e,f,g]=solve(f1,f2,f3,f4,f5,f6,f7);%this part different from code1
[a,b,c,g,d,e,f]
%end
ans =
[ 8000, 30, 60, 140, 400, 3000, 20]

Best Answer

The value stored in the output argument does not depend on the variable name. For example, you can also run your code like this
[a1,a2,a3,a4,a5,a6,z7]=solve(f1,f2,f3,f4,f5,f6,f7);
[a1,a2,a3,a4,a5,a6,z7]
Therefore in the first case when you write
b,a,c,d,e,f,g]=solve(f1,f2,f3,f4,f5,f6,f7);
it does not mean that the first output b will get the solution of the b from the equation. It will still get the solution of a variable. Therefore in both cases you are getting the same answer, only the order of variable is changed.