MATLAB: Please help with integration

integralintegration

Hi everyone. I have a problem like this
So to integrate it, I write this code:
if true
fun=@(x) (6*x)+(3*x^2);
finalfun = @(x)(180-x)*fun
S1 = integral(finalfun,0,180)
end
But it gives an error. Then I tried to put the '(180-x) inside the original function but the result is wrong. A help would be appreciated. Thanks.

Best Answer

You have to do element-wise operations and call ‘fun’ with its argument:
fun=@(x) (6*x)+(3*x.^2);
finalfun = @(x)(180-x).*fun(x);
S1 = integral(finalfun,0,180)
S1 =
268.2720e+006
Note the dot operator (.) before the exponentiation operator and the multiplication operator. See the documentation on Array vs. Matrix Operations for details.
EDIT Corrected typos.