Solving Integrals with Matlab

1 view (last 30 days)
Jerald Johnson
Jerald Johnson on 22 Apr 2019
Answered: Star Strider on 22 Apr 2019
Hi everyone, i am working on a calculus problem that requires me to use Lobatto Quadrature and Global Adaptive Quadrature but i keep getting an error. Could someone explain how to write a code for this? Thanks.
Problem: f(x)=integral sign(3x^2)dx. Upper bound is 8 and lower bound is 0 on the integral sign.
% Lobatto Quadrature
A3= quadl(@(3*x,x(1),x(end))
% Global adaptive quadrature
intfun=@(x) (3*x.^2)
A4=integral(Intfun,x(1),x(end))

Answers (1)

Star Strider
Star Strider on 22 Apr 2019
There is an error in the anonymous function in ‘A3’, and since MATLAB is case-sensitive, ‘Intfun’ is not the same as ‘intfun’. Also note that the functions for ‘A3’ and ‘A4’ are different.
This runs:
% Lobatto Quadrature
A3= quadl(@(x)3*x,x(1),x(end))
% Global adaptive quadrature
intfun=@(x) (3*x.^2)
A4=integral(intfun,x(1),x(end))
(I provided my own ‘x’ vector to test it.)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!