I have an Anonymous Function and want to integrate it

For a simple example, I have an Anonymous function A = @ (x) [x 2*x;3*x 4*x], and I want to integrate it from 0 to 1. If I use QUADV it will integrate the entire matrix A. However, it is not efficient for very large problem. I am wondering if there is a way that I can only integrate some specific terms, say only A(1,1).
The background is that I have a very large 80000 by 80000 matrix, and only a few terms need to be calculated.

回答 (2 件)

Adam
Adam 2014 年 11 月 18 日
編集済み: Adam 2014 年 11 月 18 日

0 投票

Can you not just call:
A( myMatrix(1,1) );
to evaluate just the first element of your matrix? Or
A( myMatrix( xStart:xEnd, yStart:yEnd ) );
to evaluate a rectangular subset of your matrix? Or any other form of indexing (especially linear indexing) to choose more specifically.

2 件のコメント

Yang
Yang 2014 年 11 月 18 日
Thanks Adam,
what is myMatrix?
Could u give me more details?
now I have
A = @ (x) [x 2*x;3*x 4*x]; >> quadv(A,0,1)
ans =
0.5000 1.0000
1.5000 2.0000
Could u just integrate A(1,1)?
Adam
Adam 2014 年 11 月 18 日
I'm not familiar with using quadv so its usage does complicate matters a little though I would think it should be perfectly possible.
'myMatrix' is just a place holder for whatever your matrix is which I assumed was the input x though scanning through quadv it seems your function expects only a scalar input as x so I'm not sure where your matrix comes into it.

サインインしてコメントする。

MA
MA 2014 年 11 月 18 日

0 投票

clear all
close all
clc;
syms x
A=[x 2*x;3*x 4*x];
int(A(1,1),0,1)

3 件のコメント

Yang
Yang 2014 年 11 月 18 日
Thanks M.A.!
I think int is not as efficient as quad for very large problem, so do u know if I can use numerical integration to do it?
MA
MA 2014 年 11 月 18 日
for numerical integration you can use quad , quadl or double(int())
syms x
A=[x 2*x;3*x 4*x];
double(int(A(1,1),0,1))
Mike Hosea
Mike Hosea 2014 年 11 月 20 日
Quad, quadl, and quadv are all deprecated. The function is integral(), and for array valued problems, use the 'ArrayValued',true option.
It is easy to integrate selected terms in a way that unfortunately evaluates the entire matrix, anyway. The trick is to avoid that. I'm not sure how to do it in the general context.

サインインしてコメントする。

カテゴリ

質問済み:

2014 年 11 月 18 日

コメント済み:

2014 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by