MATLAB quad and difficulty with vector input

Click For Summary
SUMMARY

The forum discussion centers on the use of the MATLAB function "quad" for numerical integration with vector inputs. The user encounters a matrix dimension error when attempting to integrate a function that includes a vector parameter 'a'. The solution proposed involves switching from "quad" to "quadv", which is designed to handle vectorized inputs more effectively. This change resolves the issue and allows for successful integration over the specified range.

PREREQUISITES
  • Understanding of MATLAB function syntax and usage
  • Familiarity with numerical integration methods in MATLAB
  • Knowledge of vector operations in MATLAB
  • Basic understanding of the sine function and its applications
NEXT STEPS
  • Learn about MATLAB "quadv" for vectorized numerical integration
  • Explore MATLAB's "integral" function for advanced integration techniques
  • Study MATLAB's error handling for matrix dimension issues
  • Investigate the use of anonymous functions in MATLAB for parameterized functions
USEFUL FOR

MATLAB users, numerical analysts, and engineers looking to perform vectorized numerical integration effectively.

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 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 9 ·
Replies
9
Views
3K