x = range(0.,π,length = 1000)
u1 = sin.(x)
u2 = cos.(x)
ip = trapz(x,prod(hcat(u1,u2),dims=2))
AssertionError: Integration axis over
yis incompatible with
x. Make sure their length match!
Can’t figure out why it’s not compatible!
x = range(0.,π,length = 1000)
u1 = sin.(x)
u2 = cos.(x)
ip = trapz(x,prod(hcat(u1,u2),dims=2))
AssertionError: Integration axis over
yis incompatible with
x. Make sure their length match!
Can’t figure out why it’s not compatible!
Works using NumericalIntegration
with exact same syntax (defaults to trapezoid rule), changing trapz
to integrate
.
Trapz.jl works with input vector instead of 1000×1 Matrix:
trapz(x,prod(hcat(u1,u2),dims=2)[:])
However, it would be simpler to broadcast the product of two arrays:
trapz(x, u1 .* u2)
Note that gaussian quadrature will likely be significantly faster.