How to Integrate Field Measurements Multiplied by COS(Z) in Matlab?

Click For Summary

Discussion Overview

The discussion revolves around integrating a set of field measurements multiplied by COS(Z) using MATLAB. Participants explore numerical integration methods and seek solutions for specific integration challenges, including the use of built-in functions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • Harry seeks to integrate field measurements as a function of Z multiplied by COS(Z) using MATLAB, specifically asking for built-in functions that can facilitate this process.
  • Another participant suggests using the trapezoidal rule (trapz) or Simpson's Rule (quad) for numerical integration, questioning whether Harry's inputs are formatted correctly.
  • Harry shares code snippets and describes an error encountered when using the quad function, indicating that it requires a function handle rather than discrete data points.
  • A participant points out that the quad and quadl functions expect symbolic or constant functions, not just a collection of discrete points, and recommends using a subset of data with trapz for integration over a specific range.

Areas of Agreement / Disagreement

Participants generally agree on the limitations of the quad function for Harry's use case and suggest alternative methods, but there is no consensus on the best approach for integrating over a specific range.

Contextual Notes

Harry's integration problem is complicated by the need to integrate over a specific range, and there are unresolved issues regarding the formatting of inputs for the quad function.

H_man
Messages
143
Reaction score
0
Hi,

I have a set of over 1000 field measurements as a function of Z. I want to multiply them by COS(Z) and integrate with respect to Z.

I have tried using the quadl function but to no avail.

Is what I want to do possible in Matlab (ie. is there a built in function for this) and if so would some kind individual let me know how?

Thanks in advance,

Harry
 
Physics news on Phys.org
H_man said:
Hi,

I have a set of over 1000 field measurements as a function of Z. I want to multiply them by COS(Z) and integrate with respect to Z.

I have tried using the quadl function but to no avail.

Is what I want to do possible in Matlab (ie. is there a built in function for this) and if so would some kind individual let me know how?

Thanks in advance,

Harry

I assume that you've got numerical data here, and not symbolic stuff, and I'll assume that "to no avail" means you get a red error message...

Can you do with Trapezoid rule integration (trapz), or Simpson's Rule (quad)?

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/trapz.html
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quad.html

Not to be patronizing (not knowing your background) but typing 'help quad' would bring up the internal MATLAB documentation for the 'quad' function (though the online documentation, as linked above, is more thorough). Perhaps you're not formatting your inputs properly?
 
Hi, the trapz function works just fine, but I need to integrate over a specific range and it just integrates all the data.

The quad function I simply can't get working. I have cut and pasted below the relevant lines of code, and the error message.

load data_2_6_08_2.txt

z_2_6 = data_2_6_08_2(:,1);
By_2_6 = data_2_6_08_2(:,2);

z = -650:650;
nn = spline (z_2_6, By_2_6, z);

q = trapz(nn);
q1 = quad(nn,1,50); %Its this line that gives me the problem%

I get the error...


? Error using ==> fcnchk at 105
FUN must be a function, a valid string expression,
or an inline function object.

Error in ==> quad at 60
f = fcnchk(funfcn);

Error in ==> TryingTheAviFilter at 12
q1 = quad(nn,1,50);

I did look at the help that comes with Matlab but did not find it helpful in this case. Any idea what I am doing wrong... I'm sure its something daft.

Thanks...

:blushing:
 
Ah... I think I see your problem!

'http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quad.html"' both expect actual symbolic (or constant) functions (or function handles). Not a collection of discrete points (see the example under the 'quad' or 'quadl' documentation where they actually go about defining a quadratic).

If you only need to (numerically) integrate over an interval, why not just take a subset of your data points, and then use 'http://www.mathworks.com/access/helpdesk/help/techdoc/ref/trapz.html"'? For instance, trapz(nn(1:50)). As per the support page, you can also use this if you have non-uniform spacing.
 
Last edited by a moderator:
Thanks! Thats a very helpful suggestion.

:smile:
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 8 ·
Replies
8
Views
10K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
10
Views
4K