Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to retrieve a parameter inside ode solver?

Subject: How to retrieve a parameter inside ode solver?

From: Qiming

Date: 21 Dec, 2012 22:52:12

Message: 1 of 3

Hi:

My question is how to retrieve a parameter value inside ode solver? Let's take the control system as an example. I write my own ODE function. Within the ODE function, I compute the control inputs as u=-K*x, where x is the system states and K is a constant matrix. x can be solved by calling ode solver, like ode45. But my question is, how can I get "u"?

I know one solution is that after running the ode solver, then I can write a for loop, like:
for i = 1 : length(x)
u(i) = -K*x(i);
end

Is there any way that I can retrieve u without using the for loop after running ode solver?

Thanks.

Subject: How to retrieve a parameter inside ode solver?

From: Torsten

Date: 22 Dec, 2012 12:49:08

Message: 2 of 3

"Qiming " <qzfyc@mst.edu> wrote in message <kb2p6s$kht$1@newscl01ah.mathworks.com>...
> Hi:
>
> My question is how to retrieve a parameter value inside ode solver? Let's take the control system as an example. I write my own ODE function. Within the ODE function, I compute the control inputs as u=-K*x, where x is the system states and K is a constant matrix. x can be solved by calling ode solver, like ode45. But my question is, how can I get "u"?
>
> I know one solution is that after running the ode solver, then I can write a for loop, like:
> for i = 1 : length(x)
> u(i) = -K*x(i);
> end
>
> Is there any way that I can retrieve u without using the for loop after running ode solver?
>
> Thanks.

I'd do it the way you suggested (after running the ODE solver), except that you will have to put u=-K*x (the loop from above is incorrect).

Best wishes
Torsten.

Subject: How to retrieve a parameter inside ode solver?

From: Qiming

Date: 23 Dec, 2012 16:29:07

Message: 3 of 3

"Torsten" wrote in message <kb4a84$nsv$1@newscl01ah.mathworks.com>...
> "Qiming " <qzfyc@mst.edu> wrote in message <kb2p6s$kht$1@newscl01ah.mathworks.com>...
> > Hi:
> >
> > My question is how to retrieve a parameter value inside ode solver? Let's take the control system as an example. I write my own ODE function. Within the ODE function, I compute the control inputs as u=-K*x, where x is the system states and K is a constant matrix. x can be solved by calling ode solver, like ode45. But my question is, how can I get "u"?
> >
> > I know one solution is that after running the ode solver, then I can write a for loop, like:
> > for i = 1 : length(x)
> > u(i) = -K*x(i);
> > end
> >
> > Is there any way that I can retrieve u without using the for loop after running ode solver?
> >
> > Thanks.
>
> I'd do it the way you suggested (after running the ODE solver), except that you will have to put u=-K*x (the loop from above is incorrect).
>
> Best wishes
> Torsten.

Hi Torsten:

Thanks for your reply. I understand that's one way to retrieve the parameter inside ODE, however, for my real application, I generate a random value inside the ODEfunction. I cannot retrieve the parameter after running the ODE solver since I cannot get the exactly the same random value in my runfile.

I also tried using a counter inside the ODE solver. The weird thing is, the length of the counter is not the same as the length of the time step. How come this happens?

Thanks.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us