MATLAB MATLAB quad and difficulty with vector input

AI Thread Summary
The discussion centers around the use of the MATLAB function "quad" for numerical integration, specifically when handling vector inputs. The user encounters an error due to incompatible matrix dimensions when trying to pass a vector `a` into the function `testf`. The error message indicates that the operation cannot be performed because the dimensions of the matrices do not match. A suggestion is made to use "quadv" instead of "quad" to resolve the issue, as "quadv" is designed to handle vector inputs more effectively. The conversation highlights the importance of ensuring that input dimensions are compatible when using MATLAB functions for numerical computations.
PlasticOh-No
Messages
18
Reaction score
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


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

Similar threads

Replies
4
Views
1K
Replies
2
Views
1K
Replies
1
Views
5K
Replies
5
Views
2K
Replies
9
Views
3K
Back
Top