Solving Integrals with Matlab

2 次查看(过去 30 天)
Jerald Johnson
Jerald Johnson 2019-4-22
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))

回答(1 个)

Star Strider
Star Strider 2019-4-22
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.)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by