Sum Of Series Matrix version
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mustafa Sereflioglu
am 5 Jun. 2020
Kommentiert: Mustafa Sereflioglu
am 7 Jun. 2020
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 k
F(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)
please someone can help me?
Sincerely yours,
M.S.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 5 Jun. 2020
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?
You could just hard-code it in terms of z.
Or if you intention is to produce a function for numeric use, write it in terms of
syms x0 [2 1]
syms x1 [2 1]
syms u0 u1 R
syms 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});
The result would be a handle to a function that expected 3 parameters, z, Q, and R, with z expected to be 6 rows, and Q expected to be 2 x 2, and R expected to be scalar.
You could specialize this for particular Q R:
Q=[1 0; 0 1]; R=[0.16];
F = @(z) FQR(z, Q, R);
When you use matlabFunction with the 'vars' option and have a cell array that includes a vector of variables, then all of the variables that are in the same cell entry will be bundled into one parameter
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numbers and Precision 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!