Stopping matlab from rearranging factors

2 views (last 30 days)
Hello everyone
I've run into some problems with MATLABS tendency to rearrange factors to make the equations look prettier (i guess?). The problem is that my factors are actually yet undefined matrices - which makes the order of them important.
Is there any way to stop matlab from doing this, or any workarround. The following is an example of what i need the code to be outputting:
K2 =
[ A^4*B + A^3*B + A^2*B + A*B + B, ZK2]
[ A^9*B + A^8*B + A^7*B + A^6*B + A^5*B, A^4*B + A^3*B + A^2*B + A*B + B]
The ZK2 term isn't important. The problem is that it produces the following instead:
K2 =
[ B*A^4 + B*A^3 + B*A^2 + B*A + B, ZK2]
[ B*A^9 + B*A^8 + B*A^7 + B*A^6 + B*A^5, B*A^4 + B*A^3 + B*A^2 + B*A + B]
I guess this is because of A being raised to a power... Any thoughts?
Thanks in advance
Rasmus Elbæk, University of Aarhus
oh, and the whole code i use is as follows:
%K2_Opstilling.m
nhours = 1;
ncalc = 4*nhours;
syms ZK2;
syms A;
syms B;
K = sym(zeros(ncalc,1));
K2 = sym(zeros(ncalc,ncalc));
Counter = 0; %Tæller
for k = [1:ncalc] %Opstiller udtrykkene der skal stå i K1 matricen.
K(k) = A^(Counter+4)*B+A^(Counter+3)*B+A^(Counter+2)*B+A^(Counter+1)*B+A^(Counter+0)*B;
Counter = Counter + 5;
end
for k = [0:ncalc-1]; %Laver en variabel m indeholdende rækker med X antal B'er, X-1 antal A*B'er osv..
m{k+1} = ones(1,ncalc-k)*K(k+1);
Z{k+1} = ones(1,ncalc-k-1)*ZK2;
K2 = K2 + diag(m{1,k+1},-k) + diag(Z{1,k+1},+1+k);
end
K2

Answers (0)

Community Treasure Hunt

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

Start Hunting!