Make Jacobian as a function in Simulink
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to linearize the nonlinear dynamics for a 6-dimensional state x
x = f(x)
x = Ax +Bu -C
When trying to linearize in a time-varying u,x neighborhood generated sequentially in Simulink (I created MPC), the value assigned to the Jacobian A changes each period, so I am trying to create a MATLAB function block in Simulink with x,u as input and A as output.
However, I am not sure how to convert the Jacobian to a function since I cannot compute the derivative in MATLAB Function. Please tell me how to do it.
Here is what I have tried and the conditions.
・I have not tried it, but I think it is the best way to do the calculation by hand and write the result in MATLAB function.
・I have not even tried it, but I am not thinking of sending u,x generated in simulink to work space, calculate it, and send it back to simulink because it would take too much time.
・I tried to create a function in MATLAB and declare the function using coder.intrinsic, or create a function in Matlabfunction with only simple derivatives, but it said that it did not support functions with derivatives and I could not do it.
The following are the actual errors that appeared.
(1) When I try to define an external function, I get the following error message: "The function 'JACOB' (JACOB) is not supported.
The function 'JACOB' (input argument of type 'double') is undefined. In error (line 3) of 'Copy_2_of_LowThrust_MPC/Subsystem/J1_block', I got the following errors [dada,dade,dadi,dadom,dadOm,dadth,deda,dede,dedi,dedom,. dedOm,dedth,dida,dide,didi,didom,didOm,didth,domda,domde,domdi,domdom,domdOm,domdth,dOmda,dOmde,dOmdi,dOmdom,dOmdOm,dOmdth,dthda,. dthde,dthdi,dthdom,dthdOm,dthdth] = JACOB(x0,u0); Component:Simulink | Category:Model error
(2) This error appears when an expression with variables is performed within a matlab function.
The order N of the derivative must be a positive integer scalar. Error in 'Copy_2_of_LowThrust_MPC/Subsystem/J1_block' (line 19) dade = diff(dadt,e_symbolic); Error (line 102) Component:Simulink | Category:Model Error
(3) This error occurs when an external function returns with a matrix.
Either logical, char, int, fi, single, or double is required. mxarray was found. mxArrays was returned from a call to the MATLAB interpreter, but is not supported inside the expression. It may only be used as an argument for an external function.
0 comentarios
Respuestas (1)
Ver también
Categorías
Más información sobre General Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!