Thread Subject: how to compare results of simulations if simulate using continuous variable timestep?

Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: peter yamo

Date: 28 May, 2008 05:33:01

Message: 1 of 12

I am doing multidomain simulations. My model requires continuous simulation
of variable time step using ode23t. Basically, I enter an input variable to the
model, perform the simulation and then see how the model responds under
different inputs. Since different number of time steps will be used to peform
different simulations, how can I compare the results in a valid way? For
instance, I want to sum the torque of a motor in 5 simulated seconds. In
simulation A, it may take 100 simulated steps. In simulation B, it may take 150
steps. Even if the accumulated torque in simulation A is higher in reality, the
larger number of time steps required to complete simulation B may lead to the
wrong conclusion that the accumulated torque in simulation B is higher.

Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Mathieu Claeys

Date: 28 May, 2008 09:34:01

Message: 2 of 12

Hello,
As I understand it, you want to integrate some physical
output of your system, defined at unevenly spaced time
steps (is this what you mean by "sum the torque [...] in 5
simulated seconds"?). If so, I would advise you to look at
the trapz function.

If you want to integrate the difference between the two
curves, you could alternatively specify the same output
times in the Tspan vector for both simulations, and simply
trapz the difference (or abs of the difference, I don't
know from what you tell which is appropriate) of the two
curves. Or you could you try to achieve more or less the
same (to the trapz method's numerical precision in
function of time steps) by interpolating the results of
one simulation at the other simulation's time step (look
at interp1).

Hopes this helps,

Mathieu




"peter yamo" <jsv8@hotmail.com> wrote in message
<g1iqqd$6or$1@fred.mathworks.com>...
> I am doing multidomain simulations. My model requires
continuous simulation
> of variable time step using ode23t. Basically, I enter
an input variable to the
> model, perform the simulation and then see how the model
responds under
> different inputs. Since different number of time steps
will be used to peform
> different simulations, how can I compare the results in
a valid way? For
> instance, I want to sum the torque of a motor in 5
simulated seconds. In
> simulation A, it may take 100 simulated steps. In
simulation B, it may take 150
> steps. Even if the accumulated torque in simulation A is
higher in reality, the
> larger number of time steps required to complete
simulation B may lead to the
> wrong conclusion that the accumulated torque in
simulation B is higher.

Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Mathieu Claeys

Date: 28 May, 2008 09:43:02

Message: 3 of 12

Sorry, I need to make a correction. If you just want to
compare the integrals (trapz the difference between the
two curves in my post above), you could trapz simulation 1
results, then trapz simulation 2 results, and substract
both integral results. You only need to define the two
curves at the same time steps if you want to compute some
kind of norm between the curves (abs, rms value, ...)
Mathieu

Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: peter yamo

Date: 28 May, 2008 16:04:02

Message: 4 of 12

hello,

I want to see how the motor performs under different inputs
(e.g. different loads attached to the motor).

For instance:
Experiment 1: input A and calculate the accumulated torque in 5 simulated seconds.
Experiment 2: input B and calculate the accumulated torque in 5 simulated
seconds.
Experiment 3: input C and ...

After performing experiments with different inputs, I want to see which input
leads to the least motor torque. My worry is that since variable time step
method is used, even input A actually leads to the least accumulated torque
in reality, it may take more time steps to simulate than the others. Thus, the
accumulated torque from input A might become larger than the others. For
each experiment, if I just add the torque in each simulated time step during
the five simulated seconds and then compare the result with the others, I
may get incorrect answer.

Peter




"Mathieu Claeys" <mathieu.claeys-deletethis-@gmail.com> wrote in
message <g1j8u9$21h$1@fred.mathworks.com>...
> Hello,
> As I understand it, you want to integrate some physical
> output of your system, defined at unevenly spaced time
> steps (is this what you mean by "sum the torque [...] in 5
> simulated seconds"?). If so, I would advise you to look at
> the trapz function.
>
> If you want to integrate the difference between the two
> curves, you could alternatively specify the same output
> times in the Tspan vector for both simulations, and simply
> trapz the difference (or abs of the difference, I don't
> know from what you tell which is appropriate) of the two
> curves. Or you could you try to achieve more or less the
> same (to the trapz method's numerical precision in
> function of time steps) by interpolating the results of
> one simulation at the other simulation's time step (look
> at interp1).
>
> Hopes this helps,
>
> Mathieu
>
>
>
>
> "peter yamo" <jsv8@hotmail.com> wrote in message
> <g1iqqd$6or$1@fred.mathworks.com>...
> > I am doing multidomain simulations. My model requires
> continuous simulation
> > of variable time step using ode23t. Basically, I enter
> an input variable to the
> > model, perform the simulation and then see how the model
> responds under
> > different inputs. Since different number of time steps
> will be used to peform
> > different simulations, how can I compare the results in
> a valid way? For
> > instance, I want to sum the torque of a motor in 5
> simulated seconds. In
> > simulation A, it may take 100 simulated steps. In
> simulation B, it may take 150
> > steps. Even if the accumulated torque in simulation A is
> higher in reality, the
> > larger number of time steps required to complete
> simulation B may lead to the
> > wrong conclusion that the accumulated torque in
> simulation B is higher.
>


Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Steven Lord

Date: 28 May, 2008 16:47:49

Message: 5 of 12


"peter yamo" <jsv8@hotmail.com> wrote in message
news:g1iqqd$6or$1@fred.mathworks.com...
>I am doing multidomain simulations. My model requires continuous simulation
> of variable time step using ode23t. Basically, I enter an input variable
> to the
> model, perform the simulation and then see how the model responds under
> different inputs. Since different number of time steps will be used to
> peform
> different simulations, how can I compare the results in a valid way? For
> instance, I want to sum the torque of a motor in 5 simulated seconds. In
> simulation A, it may take 100 simulated steps. In simulation B, it may
> take 150
> steps. Even if the accumulated torque in simulation A is higher in
> reality, the
> larger number of time steps required to complete simulation B may lead to
> the
> wrong conclusion that the accumulated torque in simulation B is higher.

Either specify the same vector (with more than two values) as the TSPAN
input in each of your calls to ODE23T, or call ODE23T with one output (in
the documentation, this is the syntax that returns sol) and use DEVAL to
evaluate the solutions for each of your simulations at the same time steps.

--
Steve Lord
slord@mathworks.com


Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: peter yamo

Date: 28 May, 2008 17:04:03

Message: 6 of 12

Hello,

Could you please let me know how I can do this under
Configuration Parameters?

I have spent a few days to perform several long simulations already. I have
saved the workspace. Is there anything that I can do to compare existing
results obtained under different time steps?



"Steven Lord" <slord@mathworks.com> wrote in message
<g1k2bl$op6$1@fred.mathworks.com>...
>
> "peter yamo" <jsv8@hotmail.com> wrote in message
> news:g1iqqd$6or$1@fred.mathworks.com...
> >I am doing multidomain simulations. My model requires continuous
simulation
> > of variable time step using ode23t. Basically, I enter an input variable
> > to the
> > model, perform the simulation and then see how the model responds
under
> > different inputs. Since different number of time steps will be used to
> > peform
> > different simulations, how can I compare the results in a valid way? For
> > instance, I want to sum the torque of a motor in 5 simulated seconds. In
> > simulation A, it may take 100 simulated steps. In simulation B, it may
> > take 150
> > steps. Even if the accumulated torque in simulation A is higher in
> > reality, the
> > larger number of time steps required to complete simulation B may lead
to
> > the
> > wrong conclusion that the accumulated torque in simulation B is higher.
>
> Either specify the same vector (with more than two values) as the TSPAN
> input in each of your calls to ODE23T, or call ODE23T with one output (in
> the documentation, this is the syntax that returns sol) and use DEVAL to
> evaluate the solutions for each of your simulations at the same time steps.
>
> --
> Steve Lord
> slord@mathworks.com
>
>


Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Steven Lord

Date: 28 May, 2008 20:46:33

Message: 7 of 12


"peter yamo" <jsv8@hotmail.com> wrote in message
news:g1k3a2$7sq$1@fred.mathworks.com...
> Hello,
>
> Could you please let me know how I can do this under
> Configuration Parameters?

Oh, you're doing this in Simulink. When you mentioned ode23t in your
original posting, I assumed you were referring to the M-file function.

I'm not exactly sure how to do what I suggested from the Simulink
environment (I tend to focus more on the MATLAB side of things) -- if no one
replies with instructions soon (within the next few hours or so) I recommend
you contact Technical Support.

--
Steve Lord
slord@mathworks.com


Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: peter yamo

Date: 29 May, 2008 01:41:03

Message: 8 of 12

Thanks. At this stage, I am more concerned with processing the already
obtained experimental data. I did save the joint data along with time (e.g.
Joint.time) in the workspace.


"Steven Lord" <slord@mathworks.com> wrote in message
<g1kgb9$8p7$1@fred.mathworks.com>...
>
> "peter yamo" <jsv8@hotmail.com> wrote in message
> news:g1k3a2$7sq$1@fred.mathworks.com...
> > Hello,
> >
> > Could you please let me know how I can do this under
> > Configuration Parameters?
>
> Oh, you're doing this in Simulink. When you mentioned ode23t in your
> original posting, I assumed you were referring to the M-file function.
>
> I'm not exactly sure how to do what I suggested from the Simulink
> environment (I tend to focus more on the MATLAB side of things) -- if no
one
> replies with instructions soon (within the next few hours or so) I
recommend
> you contact Technical Support.
>
> --
> Steve Lord
> slord@mathworks.com
>
>


Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Shankar Akella

Date: 29 May, 2008 04:19:02

Message: 9 of 12

Hi
"peter yamo" <jsv8@hotmail.com> wrote in message
<g1iqqd$6or$1@fred.mathworks.com>...
> I am doing multidomain simulations. My model requires
continuous simulation
> of variable time step using ode23t. Basically, I enter an
input variable to the
> model, perform the simulation and then see how the model
responds under
> different inputs. Since different number of time steps
will be used to peform
> different simulations, how can I compare the results in a
valid way? For
> instance, I want to sum the torque of a motor in 5
simulated seconds. In
> simulation A, it may take 100 simulated steps. In
simulation B, it may take 150
> steps. Even if the accumulated torque in simulation A is
higher in reality, the
> larger number of time steps required to complete
simulation B may lead to the
> wrong conclusion that the accumulated torque in simulation
B is higher.


One easy solution which is similar to What Steven Lord
suggested is as follows.
Come up with a time vector for example t1 = [0,1,2,3,4,5]
Then from the simulation results compute torques at these
time intervals using interpolation (for interpolation you
can use any interp functions available in matlab). Then you
can compare the accumulated torques.

I hope this helps.

Best regards

Shankar

Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: peter yamo

Date: 30 May, 2008 00:09:02

Message: 10 of 12

Hello,

Thank you for all the suggestions. I came up with a time vector t1 = [0, 0.1,
0.2, 0.3, ..., 5]. Then, I looked at the corresponding torque (which I saved
earlier during the experiments) at these evenly spaced discrete time point.
Doing the same thing for each experiment allows me to compare the
accumulated torque. In that case, could you please let me know why I need to
interpolate the data?



"Shankar Akella" <sakella72.nospam@gmail.com> wrote in message
<g1larm$rmm$1@fred.mathworks.com>...
> Hi
> "peter yamo" <jsv8@hotmail.com> wrote in message
> <g1iqqd$6or$1@fred.mathworks.com>...
> > I am doing multidomain simulations. My model requires
> continuous simulation
> > of variable time step using ode23t. Basically, I enter an
> input variable to the
> > model, perform the simulation and then see how the model
> responds under
> > different inputs. Since different number of time steps
> will be used to peform
> > different simulations, how can I compare the results in a
> valid way? For
> > instance, I want to sum the torque of a motor in 5
> simulated seconds. In
> > simulation A, it may take 100 simulated steps. In
> simulation B, it may take 150
> > steps. Even if the accumulated torque in simulation A is
> higher in reality, the
> > larger number of time steps required to complete
> simulation B may lead to the
> > wrong conclusion that the accumulated torque in simulation
> B is higher.
>
>
> One easy solution which is similar to What Steven Lord
> suggested is as follows.
> Come up with a time vector for example t1 = [0,1,2,3,4,5]
> Then from the simulation results compute torques at these
> time intervals using interpolation (for interpolation you
> can use any interp functions available in matlab). Then you
> can compare the accumulated torques.
>
> I hope this helps.
>
> Best regards
>
> Shankar
>


Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Shankar Akella

Date: 30 May, 2008 04:07:01

Message: 11 of 12

Hi

If you have torque data for the selected points then you do
not need to do interpolation. You need to do interpolation
only if you do not have torque data for a given time in the
time vector.

Best regards

Shankar

"peter yamo" <jsv8@hotmail.com> wrote in message
<g1ngiu$i6s$1@fred.mathworks.com>...
> Hello,
>
> Thank you for all the suggestions. I came up with a time
vector t1 = [0, 0.1,
> 0.2, 0.3, ..., 5]. Then, I looked at the corresponding
torque (which I saved
> earlier during the experiments) at these evenly spaced
discrete time point.
> Doing the same thing for each experiment allows me to
compare the
> accumulated torque. In that case, could you please let me
know why I need to
> interpolate the data?
>
>
>
> "Shankar Akella" <sakella72.nospam@gmail.com> wrote in
message
> <g1larm$rmm$1@fred.mathworks.com>...
> > Hi
> > "peter yamo" <jsv8@hotmail.com> wrote in message
> > <g1iqqd$6or$1@fred.mathworks.com>...
> > > I am doing multidomain simulations. My model requires
> > continuous simulation
> > > of variable time step using ode23t. Basically, I enter an
> > input variable to the
> > > model, perform the simulation and then see how the model
> > responds under
> > > different inputs. Since different number of time steps
> > will be used to peform
> > > different simulations, how can I compare the results in a
> > valid way? For
> > > instance, I want to sum the torque of a motor in 5
> > simulated seconds. In
> > > simulation A, it may take 100 simulated steps. In
> > simulation B, it may take 150
> > > steps. Even if the accumulated torque in simulation A is
> > higher in reality, the
> > > larger number of time steps required to complete
> > simulation B may lead to the
> > > wrong conclusion that the accumulated torque in simulation
> > B is higher.
> >
> >
> > One easy solution which is similar to What Steven Lord
> > suggested is as follows.
> > Come up with a time vector for example t1 = [0,1,2,3,4,5]
> > Then from the simulation results compute torques at these
> > time intervals using interpolation (for interpolation you
> > can use any interp functions available in matlab). Then you
> > can compare the accumulated torques.
> >
> > I hope this helps.
> >
> > Best regards
> >
> > Shankar
> >
>
>

Subject: how to compare results of simulations if simulate using continuous variable timestep?

From: Mathieu Claeys

Date: 30 May, 2008 07:22:02

Message: 12 of 12

Dear Peter,
Looking at your posts, I really think you want to compare
average values of continuous signals over the same time
span.
As the average value of a continuous function is its
integral over that time span divided by the time span, I
still strongly suggest you use a suitable numerical
integration method, such as trapz. Code would look like:

average_torque_1 = trapz(results1.time,results1.torque)/
(results1.time(end)-results1.time(1));

and the like for other simulation results. Then you
compare average torques in between them and choose which
is the best (the highest, the lowest, the one closest to a
desired value,...).

Interpolating at evenly spaced time steps, then summing
up, is essentially the same except you're doing extra
calculation to loose a lot of precision (especially if the
problem is somehow stiff, which is probably why you use
ode23t).

I hope this helps,

Mathieu

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
compare result peter yamo 28 May, 2008 01:35:05
ode23t peter yamo 28 May, 2008 01:35:04
variable time step peter yamo 28 May, 2008 01:35:04
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com