Issue with formulating an expression using nested trapz

2 views (last 30 days)
I want to double integrate with the given data points. The expression is
q(i)*f(i,j)/(1+q(i)*f(i,j))
where f is 11X11 matrix and q is a 1X11 matrix. All the data points are given for these matrices.
x=linspace(1,11,11);
y=linspace(1,11,11);
[X,Y]=meshgrid(x,y);
f=R1; R1 already had the data points which is stored in f as 11X11 matrix
q=E(x);
I=trapz(x,q.*trapz(y,f));
How to write the given expression in nested trapz form.
In the last line of code, I'm stuck
The problem I'm facing that q and f are only just data points. They are not any specific function which can be Mapped in X-Y meshgrid (Not Sure).

Answers (1)

John BG
John BG on 30 Jan 2016
Try this
x=[0:.1:11]
y=[0:.1:11]
[X,Y]=meshgrid(x,y) % integration area R1: 12x12
q=[1:1:11] % the 1D parameter you have defined
before integrating let's have a look to the function for k=1 q(k)=1
R=(X^2+Y^2).^.5
F2=(R./(1+R)).^.5
mind the points to make sure element-to-element don't go array and the result is Complex
before integrating it's also recommended to have a look to the function just in case there are negative values that may reduce the result inadvertently
F=q(k)*(X.^2+Y.^2)^.5./(1+q(k)*sqrt(X.^2+Y.^2)^.5)^.5
surf(X,Y,F2)
Now integrate, with the nested trapz you asked for:
I=trapz(y,trapz(x,F,2))
I = 1.201913622981376e+02
now you may want q to sweep:
F3=(q(k)*R./(1+q(k)*R)).^5
I3=zeros(1,length(q))
for k=1:1:length(q)
I3(k)=trapz(y,trapz(x,F3,2))
end
for the given values of q the integral is always the same
stem(I3)
var(I3)
ans = 2.221432309102369e-28
If interested on the primitive, MuPAD (Symbolic Toolbox required) shows the following integration primitive:
that as complicated as it seems, it is not. The imaginary part is null atan(i)=0 and the real part is independent of r, yielding an apparently absurd 1/0 that is the way MuPAD has to say 'don't know this way, try with limits'. But we have already seen that the function is constant for large R.
If you find this answer useful please click on the thumbs up and flag above thanks in advance John
  2 Comments
Rabindra Biswas
Rabindra Biswas on 31 Jan 2016
Thanks john
but my problem is, in your case the F is a specific function mapped into X-Y meshgrid. I have only data points.Not any specific function.
John BG
John BG on 9 Feb 2016
thid you posted above 'q(i)*f(i,j)/(1+q(i)*f(i,j))' looks like a function.
ok, double-integration sounds like volume. It doesn't really matter whether you have defined function or a group of points, as long as there is a primitive, or a function, or group of points that derived give your points, MATLAB integration quad takes any quad input as vectors.
Make the data available here by clicking on the clip icon to attach the file to another comment.
John

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!