# MATLAB: Sum Of Series Matrix version

matrixsum of series

Hello,
i have a Question and dont know how to continue… I need some help :)!
these are x0 this is u0 these are x1 this is u1
i have a Vector called z=[ 1; 1; 3; 0; 0; 0]; With Q=[1 0; 0 1]; and R=[0.16];
my Aim is to build a Function, like this:
``x0.'*Q*x0 + u0.'*R*u0 + x1.'*Q*x1 + u1.'*R*u1;                          %(1)``
to build x0 i have to grab from z(1:2), for u0 z(3). and so on…
How am i going to do this?
i tryed symsum but dont know how to do it.
``syms x kF(z) = symsum(z.'*Q*z + z.'*R*z ,k,0,1); ``
the problem, when iam doing this, is, iam gonna have
``F(z) = z.'*Q*z + z.'*R*z + z.'*Q*z + z.'*R*z + z.'*Q*z + z.'*R*z ``
in this form i will not be able to write x0,u0 to the correct spots. because if i go with this for exmaple
x0 correct here has to be u0 here x1 here u1 like (1)
F(z(1:2))= z(1:2).'*Q*z(1:2) + z(1:2).'*R*z(1:2) + z(1:2).'*Q*z(1:2) + z(1:2).'*R*z(1:2)
``to build x0 i have to grab from z(1:2), for u0 z(3). and so on... How am i going to do this?``
``syms x0 [2 1]syms x1 [2 1]syms u0 u1 Rsyms Q [2 2]f = x0.'*Q*x0 + u0.'*R*u0 + x1.'*Q*x1 + u1.'*R*u1;FQR = matlabFunction(f, 'vars', {[x0;u0;x1;u1], Q, R});``
``Q=[1 0; 0 1]; R=[0.16];F = @(z) FQR(z, Q, R);``