MATLAB quad and difficulty with vector input

In summary, MATLAB quad is a numerical integration function used for solving definite integrals. To use it, you need to provide the function, limits of integration, and optional parameters. It also supports vector input, which allows for efficient computation of multiple integrals at once. To input vectors, you can use the <code>arrayfun</code> or <code>integral</code> functions. Difficulty with vector input may be due to the function not being vectorized or not defined over the entire input.
  • #1
PlasticOh-No
18
0
MATLAB "quad" and difficulty with vector input

Hello all.

Consider the following:

function y = testf(x,a)
y = sin(pi.*a.*x);

...and then we have

a = 0.05:0.05:1;
result1 = quad(@(x)testf(x, a),0,1)

which crashes with

? Error using ==> times
Matrix dimensions must agree.

Can you help?
Thank you.
 
Physics news on Phys.org
  • #2


Oops. Is this just a matter of using quadv instead of quad?
 

1. What is MATLAB quad?

MATLAB quad is a numerical integration function in MATLAB that approximates the integral of a given function over a specified interval. It is commonly used for solving definite integrals.

2. How do I use MATLAB quad?

To use MATLAB quad, you need to provide the function you want to integrate, the limits of integration, and any additional parameters. The syntax is quad(fun, a, b, [options]), where fun is the function to be integrated, a and b are the limits of integration, and [options] are optional parameters such as tolerance and maximum number of function evaluations.

3. What is vector input in MATLAB quad?

Vector input in MATLAB quad refers to providing arrays or matrices as input for the function to be integrated. This allows for efficient computation of multiple integrals at once.

4. How do I input vectors in MATLAB quad?

To input vectors in MATLAB quad, you can use the arrayfun function to apply the integration function to each element of the vector. You can also use the integral function for vector inputs, which uses a different algorithm than quad but can still provide accurate results for vector inputs.

5. Why am I having difficulty with vector input in MATLAB quad?

One possible reason for difficulty with vector input in MATLAB quad is that the function being integrated is not vectorized, meaning it cannot accept arrays as input. In this case, you can use the arrayfun function as mentioned in the previous answer. Another reason could be that the function is not defined over the entire vector input, so you may need to break it up into smaller intervals and integrate each interval separately.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
572
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top