Why do I get an error message when I try to use the functions QUAD and QUADL?
2 views (last 30 days)
Show older comments
I receive one of the following messages when I try to pass my inline function or function handle to the QUAD function:
??? Error using ==> .*
Matrix dimensions must agree.
??? Error using ==> *
Inner matrix dimensions must agree.
??? Error using ==> *
Inner matrix dimensions must agree.
???Error using ==> ^
Matrix must be square
Why do I receive these errors and how do I correct the problem?
Accepted Answer
MathWorks Support Team
on 22 Jan 2010
These errors occur because the function that you are trying to integrate, the integrand, is not defined correctly for use with QUAD and QUADL. You need to write the function in such a way that QUAD/QUADL can accept a vector of values for the dependent variable. This means that the output of F, the function you are integrating, should be the same size as the inputs. Your function F should work as follows with a vector of any size:
f([a b]) = [f(a) f(b)] %where a and b are scalar values
f([a;b]) = [f(a);f(b)] %where a and b are scalar values
So if you wanted to integrate the function y=x^3, you would need to write it like this:
y = @(x) x.^3;
q = quad(y,0,1);
rather than like this:
y = @(x) x^3;
q = quad(y,0,1);
If you are using a version of MATLAB older than MATLAB 7.0 (R14), you will need to use a function file or an inline function to define the integrand. To perform this integration using an inline function, try:
y=inline('x.^3');
q=quad(y,0,1);
rather than:
y=inline('x^3');
q=quad(y,0,1);
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!