1. URGENT: MATLAB quad function frustration

Hi all,

I'm trying to use the built-in MATLAB function quad to integrate the following function :

$\int_{0}^{2\pi}\ x * sin (x) \ dx$ but its not working for me.

Now when I use the quad function to evaluate

$\int_{0}^{2\pi}\ x \ dx$ I get the correct answer.

When I use the quad function to evaluate

$\int_{0}^{2\pi}\ sin (x) \ dx$ I get the correct answer.

but when I use the quad function to evaluate

$\int_{0}^{2\pi}\ x * sin (x) \ dx$

I get the output

??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> myfun at 7
y = sin(x) * x ;

Error in ==> quad at 77
y = f(x, varargin{:});

where myfun is the mfile I wrote .........

function y = myfun(x)
y = sin(x) * x ;

Also this is what I type into the MATLAB command window when I try and use the quad function

What am I doing wrong here? Im no expert in MATLAB and Im not sure how to get around this.

2. Nevermind, I realised that I had to vectorize my mfile by changing it to

function y = myfun(x)
y = x.*sin(x);

3. Originally Posted by woody198403
Hi all,

I'm trying to use the built-in MATLAB function quad to integrate the following function :

$\int_{0}^{2\pi}\ x * sin (x) \ dx$ but its not working for me.

Now when I use the quad function to evaluate

$\int_{0}^{2\pi}\ x \ dx$ I get the correct answer.

When I use the quad function to evaluate

$\int_{0}^{2\pi}\ sin (x) \ dx$ I get the correct answer.

but when I use the quad function to evaluate

$\int_{0}^{2\pi}\ x * sin (x) \ dx$

I get the output

??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> myfun at 7
y = sin(x) * x ;

Error in ==> quad at 77
y = f(x, varargin{:});

where myfun is the mfile I wrote .........

function y = myfun(x)
y = sin(x) * x ;

Also this is what I type into the MATLAB command window when I try and use the quad function

What am I doing wrong here? Im no expert in MATLAB and Im not sure how to get around this.
u need to put dot before multiplication sign(array)...try this

4. Originally Posted by woody198403
Hi all,

I'm trying to use the built-in MATLAB function quad to integrate the following function :

$\int_{0}^{2\pi}\ x * sin (x) \ dx$ but its not working for me.

Now when I use the quad function to evaluate

$\int_{0}^{2\pi}\ x \ dx$ I get the correct answer.

When I use the quad function to evaluate

$\int_{0}^{2\pi}\ sin (x) \ dx$ I get the correct answer.

but when I use the quad function to evaluate

$\int_{0}^{2\pi}\ x * sin (x) \ dx$

I get the output

??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> myfun at 7
y = sin(x) * x ;

Error in ==> quad at 77
y = f(x, varargin{:});

where myfun is the mfile I wrote .........

function y = myfun(x)
y = sin(x) * x ;

Also this is what I type into the MATLAB command window when I try and use the quad function