Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

So I have another matlab problem

  1. Apr 4, 2007 #1
    Should be a simple one, just can't get it to work. Basically, I have two sets of data that I want to compare. One set of data was observed at set intervals of time, and the second set of data is calculated - the problem is that the theoretical data has entries for non-integer values of t - when the observed is in single integer steps.

    This means that for the period of a minute in the theoretical data, I'll have several values but only a single observed value. Unfortunately, the number of theoretical values in a given range differs throughout so I feel that the best way to sort this out would be to lose a bit of accuracy and plot the observed data then somehow automatically calculate a point for each bit in time which would correspond to my theoretical. Is this possible?
  2. jcsd
  3. Apr 4, 2007 #2

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Plot both data sets and compare them or alternatively using the theoretical model, calculate the values given the experimental t's then plot and compare.
  4. Apr 4, 2007 #3
    I would calculate the experimental t's, but the theoretical data is calculated in an ODE solver with a defined tolerance (as far as I know, theres no way to define a definite step in ODE solvers, only an initial suggestion?). Leaves me with plotting the two results, is there any way to subtract two plots? Just to give a nicer comparison.
  5. Apr 4, 2007 #4

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Take the experimental output and the theoretical output and do a term by term search for the coincident times and subtract them.

    I'd just plot both then make the comparision, it'd look better to me and more professional.
  6. Apr 4, 2007 #5
    If you're using Matlab's ODE solver you can give it the time values at which you want the solution. Also, you can use the interp functions to interpolate your solution down to the coarser time grid.
  7. Apr 4, 2007 #6

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Very true......Forgot about those functions.
  8. Apr 5, 2007 #7
    thanks, advice appreciated

    How do I force the ODE solver to take specific time values? Will that affect the accuracy of the solutions it finds at those points? As far as I knew (this is the first time I've used multiple ODE solvers in matlab) all I can do is give the solver an initial step suggestion and let it work through relative/absolute error tolerances to find the rest. thanks also, many a-far-more knowledgeable than I.
    Last edited: Apr 5, 2007
  9. Apr 5, 2007 #8


    User Avatar

    It seems to me a bit dangerous interpolating the experimental data -- eg. the theoretical data could show much higher frequency dynamics than the experimental data.

    In which case, I would average out the theoretical data according to the time scale of the device used to measure the experimental stuff.
  10. Apr 5, 2007 #9
    If tspan is the time input argument to the ode solver, before you had
    tspan = [t0, tf]
    where t0 is the starting time and tf is the final time, just change it to
    tspan = [t0, t1, t2, t3, t4, tf]
    where t0,t1,t2,... are the points you want the solution at. And no, it does not affect the accuracy of the integration scheme, the ode solver solves it at many more points but only returns values for the specified points.

    This is what I meant by interpolate down to the coarser time scale.
  11. Apr 8, 2007 #10
    excellent. Very much appreciated LeBrad.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook