hondaguy All American 6409 Posts user info edit post |
a data set in Matlab?
I have a data set that I need to graph and then find the area under the curve. 2/12/2007 9:28:25 PM |
strudle66 All American 1573 Posts user info edit post |
i just looked under the help, searcher "integrate data"
Quote : | "Can I integrate a set of sampled data?
Not directly. You have to represent the data as a function by interpolation or some other scheme for fitting data. The smoothness of this function is critical. A piecewise polynomial fit like a spline can look smooth to the eye, but rough to a solver; the solver takes small steps where the derivatives of the fit have jumps. Either use a smooth function to represent the data or use one of the lower order solvers (ode23, ode23s, ode23t, ode23tb) that is less sensitive to this." |
but i would think there is another way
perhaps you can calculate your area by summing the y-values multiplied by the step width in your x-values?
EDIT:
the function "trapz" looks to be the one, check it out in the help
[Edited on February 12, 2007 at 9:37 PM. Reason : trapz]2/12/2007 9:35:04 PM |
hondaguy All American 6409 Posts user info edit post |
well shit, i keep getting an error when i try to run matlab through putty
and I need this before I can finish my lab report that is due tomorrow
[Edited on February 12, 2007 at 9:59 PM. Reason : ] 2/12/2007 9:49:24 PM |
strudle66 All American 1573 Posts user info edit post |
might need a trip to broughton tonight
if its just plotting the data and getting the area, send me the data and your code to plot/calculate it, and i'll run it and paste it in word and send it back. rstruzik@gmail.com 2/12/2007 10:02:12 PM |
nonlogic All American 1252 Posts user info edit post |
Matlab typically runs through GUI, so it won't work directly on Putty. If you run XWin with Putty, Matlab will usually be fine. 2/12/2007 10:05:47 PM |
hondaguy All American 6409 Posts user info edit post |
I think you might be right about that trip to broughton . . . although i'm not sure what time those labs close now
I would take you up on your offer, but I don't even have that code in front of me.
^I am running X-win32 and Putty. It says "Fatal Java Exception Detected"
[Edited on February 12, 2007 at 10:08 PM. Reason : ] 2/12/2007 10:06:37 PM |
strudle66 All American 1573 Posts user info edit post |
^ that shit always lagged like hell for me, if you're close enough it's easier to just go to campus
edit:
i think broughton closes at 11
dh hill is open 24hrs mon-thurs
or laundry labs should be open all night i think
[Edited on February 12, 2007 at 10:12 PM. Reason : times] 2/12/2007 10:09:52 PM |
Lowjack All American 10491 Posts user info edit post |
newton's method. 2/12/2007 10:16:23 PM |
BigMan157 no u 103354 Posts user info edit post |
Daniels had the 24hr engineering computer lab last i checked, though that was a year ago
[Edited on February 12, 2007 at 10:18 PM. Reason : on the 1st or 2nd floor] 2/12/2007 10:18:02 PM |
HEAVYCRAIG Veteran 200 Posts user info edit post |
You could always just use excel to plot the data and use Simpson's rule for the area unless you have a lot of data points. 2/12/2007 10:21:20 PM |
hondaguy All American 6409 Posts user info edit post |
^I have 12 data points . . . what is simpson's rule again? 2/12/2007 10:34:22 PM |
chembob Yankee Cowboy 27011 Posts user info edit post |
%Define the function to integrate (using anonymous functions) f = @(x) x^2;
%Set the interval to integrate a = -1; b = 1; %set the number of panels to compute and their length n = 100; h = (b-a)/n;
%split up the interval into subintervals x = [a:h:b]; %note that matlab matrices are indexed starting at 1 sum = f(x(1)); for i=2:2:n sum = sum + 4*f(x(i)); end; for i=3:2:n-1 sum = sum + 2*f(x(i)); end; %prints out the result f_integrated = (h/3)*(sum + f(x(n+1)))
http://en.wikipedia.org/wiki/Simpson%27s_rule#Matlab_implementation_of_composite_Simpson.27s_rule2/12/2007 10:37:32 PM |
hondaguy All American 6409 Posts user info edit post |
yeah, I remembered Simpsons rule shortly after I posted that
I just did it in excel real quick . . . not hte most accurate, but it'll do for now
/thread
[Edited on February 12, 2007 at 10:43 PM. Reason : thx everyone] 2/12/2007 10:42:44 PM |
virga All American 2019 Posts user info edit post |
um...
if you have a discrete set of points, you don't really integrate that. the discrete version of an integral is just a summation. like deltax*sumofdata. if you have an explicit that you want matlab to numerically integrate, than you define the function either as an m file or as an anonymous function and then use the quad command:
help quad
which uses i think gaussian quadratures to evaluate. simpsons rule uses parabolic quads. anyways..have fun. 2/13/2007 4:32:06 PM |