MatLab Matrix Help: Integrating for Entries Equal to 1

Just because it works on scalars doesn't mean it works on arrays.In summary, the conversation discusses using Matlab to calculate the integral of x from 0 to a given value in matrix A, based on a corresponding entry of 1 in matrix B. The quad function is not recommended by Matlab, and the integral function should be used instead. There may be a way to avoid using a "for i, for j" statement, such as using the ARRAYFUN function, but it is not guaranteed to work in all cases.
  • #1
Apteronotus
202
0
Hi,

I have a quick question regarding MatLab.

I have 3 matracies A, B and C.

For every entry equal to 1 in B, I want to let the corresponding entry in A be an integral of x from 0 to C.

ex.
for all (i,j)
if B(i,j)==1 then let A(i,j)=quad(@(x) x, 0, C(i,j))

A quick way to do this for large matracies I thought was to use the following syntax:
A(B==1) = quad(@(x) x, 0, C(B==1))

But get the following error:
? Error using ==> quad at 70
The limits of integration must be scalars.


Is there any way around this other than a "for i, for j" statement?

Thanks,
 
Physics news on Phys.org
  • #3
I haven't tried it, but ARRAYFUN may be what OP is looking for.

https://www.mathworks.com/help/matlab/ref/arrayfun.html
But just a general comment, don't assume a function is automatically vectorized unless the documentation explicitly says it is.
 

1. What is MatLab Matrix Integration?

MatLab Matrix Integration is the process of performing mathematical operations on a matrix, such as addition, subtraction, multiplication, and division. It allows for the manipulation and analysis of large sets of data in a more efficient and organized manner.

2. How can I integrate for entries equal to 1 in a matrix using MatLab?

To integrate for entries equal to 1 in a matrix using MatLab, you can use the find function to locate all the indices of 1 in the matrix. Then, you can use the sum function to add up all the values in those indices.

3. Can I integrate for specific entries in a matrix using MatLab?

Yes, you can integrate for specific entries in a matrix using MatLab. You can use the find function to locate the indices of the specific entries you want to integrate for, and then use the sum function to add up the values in those indices.

4. What is the difference between integrating for entries equal to 1 and summing them?

The difference between integrating for entries equal to 1 and summing them is that integration involves finding the area under a curve, while summing simply adds up the values in a set of data. In the context of matrices, integrating for entries equal to 1 would involve finding the area under a specific set of values, whereas summing them would just add up those values without considering their position in the matrix.

5. Can I integrate for entries equal to 1 in a specific row or column of a matrix?

Yes, you can integrate for entries equal to 1 in a specific row or column of a matrix by using the sum function along with the find function to locate the indices of 1 in that particular row or column. This will add up all the values in that row or column which are equal to 1.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
122
Back
Top