필터 지우기
필터 지우기

Create a matrix that changes size according to a variable N

조회 수: 11 (최근 30일)
wissal zaher
wissal zaher 2022년 7월 10일
댓글: Steven Lord 2022년 7월 11일
Hello,
I'm working on a project consisting of creating an MPC controller from scratch and the matrices need to be defined in a way where the size can change given a variable N (the prediction Horizon). I've already wirtten the matrices for N=7 but how can I do so for a flexible N input.
The size of the Matrices is given below.
A,B,Q,R, x_min, x_max, u_min, u_max are defined as follow :
A = [1 0.1;0 1]
B = [0.005;0.1]
Q = [1 0;0 1]
R = 0.1
x_min = [-5;-5]
x_max = [5;5]
u_min = -1
u_max = 1

채택된 답변

patrick1704
patrick1704 2022년 7월 10일
Well, one option on how to e.g. create your is to do something like this:
Atilde = arrayfun(@(x) A.^x, 0:1:n, 'UniformOutput',false).';
Atilde = vertcat(Atilde{:});
Naturally, doing everything in a for-loop using if-clauses is also an option. It mainly depends on how efficient you need the implementation to be.
  댓글 수: 2
wissal zaher
wissal zaher 2022년 7월 11일
편집: wissal zaher 2022년 7월 11일
For Atilde it worked nicely :)
Bor Btilde I think I have to create a loop .. any ideas ?
And thank you for the reply
Steven Lord
Steven Lord 2022년 7월 11일
Bor Btilde I think I have to create a loop .. any ideas ?
Create a for loop?
You may have heard that "for loops in MATLAB are slow." At one time, years ago, that may have been true. It has become less and less true as we've enhanced the language.
If for loops are the right tool for the job, use them.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Controller Creation에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by