How to code recursive function of a function with dependent variable inside?? sorry, I dont know how to explain.
10 次查看(过去 30 天)
显示 更早的评论
My program is very difficult, I do not know how to write please help.
The goal of my program is to find vector of variable u which can be compute by using 3 equation, 2 are recursive.
let i be index in a vector array, and function f depend on vector x and u.
1. state x_i+1 = x_i +f( x_i , u_i ) , with x_0 is given
2. cosatate lambda_i = lambda_i+1 + H( x_i , lambda_i+1 , u_i), with last value of lambda is given and H is a function depend on previous lambda, x and u.
It can be seen that fist I have to find state subsequent x by forward recursive and then lambda by backward recursive. After that I must sub these two arrays in to the final function.
3. function F( x,lambda,u )
From third equation, the only variable left is u. Then, I will use some method like fsolve to find the value of u later.
Please help, because I cannot write function F by myself because it compose by very complicated equation as I explain above.
0 个评论
回答(1 个)
Panagiotis Panos Katranitsas
2012-2-25
Hi Tang, generally when you have to calculate recursive equations you need to initialise that parameters and then use them inside a loop.
Please have a look at the following code, I calculate the Qt based on Qt-1. The A,B,u,Proc_noise are constants. This code is for kalman filter.
Q= [0]; %initized state
for t = 0 : sampling: duration
Q= A * Q+ B * u + Proc_noise; <== Check that line
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!