So I have another matlab problem

  • MATLAB
  • Thread starter fasterthanjoao
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses a problem with comparing two sets of data with different time intervals. The solution proposed is to plot both data sets and compare them, or to use the theoretical model to calculate values for the experimental time intervals and then compare. It is suggested to use Matlab's ODE solver and interpolation functions to interpolate the solution to the coarser time grid. It is also mentioned that the solver can be forced to take specific time values without affecting accuracy. There is also a discussion about the potential danger of interpolating the experimental data and the suggestion to average out the theoretical data according to the time scale of the device used to measure the experimental data.
  • #1
fasterthanjoao
731
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?
 
Physics news on Phys.org
  • #2
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.
 
  • #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, there's 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.
 
  • #4
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.
 
  • #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.
 
  • #6
LeBrad said:
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.


Very true...Forgot about those functions.
 
  • #7
Dr Transport said:
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.

thanks, advice appreciated

LeBrad said:
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.

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:
  • #8
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.
 
  • #9
fasterthanjoao said:
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.

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.


J77 said:
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.

This is what I meant by interpolate down to the coarser time scale.
 
  • #10
excellent. Very much appreciated LeBrad.
 

FAQ: So I have another matlab problem

1. What is Matlab and how is it used in scientific research?

Matlab is a high-level programming language and interactive environment commonly used in scientific research to manipulate, analyze, and visualize data. It allows scientists to perform complex calculations and create sophisticated algorithms, making it a valuable tool in fields such as mathematics, engineering, and physics.

2. What are the common challenges when solving a problem using Matlab?

Some common challenges when using Matlab include understanding the syntax and structure of the language, debugging errors, and optimizing code for efficiency. It is important to have a strong understanding of mathematical concepts and algorithms in order to effectively use Matlab for problem-solving.

3. What are the steps to solving a problem using Matlab?

The first step is to clearly define the problem and identify the necessary inputs and desired outputs. Next, develop an algorithm or plan for solving the problem. Then, code the algorithm in Matlab, test it, and make any necessary revisions. Finally, run the code and analyze the results to ensure they align with the desired outputs.

4. How can I improve my skills in using Matlab?

Practice and experimentation are key to improving skills in using Matlab. There are also many online resources and tutorials available, as well as courses and workshops offered by Matlab itself. Additionally, collaborating with other researchers and discussing different approaches to problem-solving can also help improve skills in using Matlab.

5. Are there any common mistakes to avoid when using Matlab?

Some common mistakes to avoid when using Matlab include not properly defining variables, using incorrect syntax, and not debugging code for errors. It is also important to regularly save work and backup code in case of any unexpected errors or crashes.

Similar threads

Replies
1
Views
2K
Replies
1
Views
1K
Replies
12
Views
3K
Replies
12
Views
3K
Replies
3
Views
7K
Replies
1
Views
905
Replies
2
Views
3K
Back
Top