Hi I need help with trap() function

How do I properly retype my code by using trap() function?
this is the original code, I run it I got .5, but when I plug in with trap() form i got like 10 different number, how do I properly use trap() function
this is a trapezoid method integral problem

  a = 0 ; b = 1
  n = 10
  h = (b-a)/n
  y = f_x(x)

first of all, when asking for help about somewhat obscure functions outside of base, its always good practice to state what package you are trying to use, so that people don't have to search.
assume you are using cmna ? https://www.rdocumentation.org/packages/cmna/versions/1.0.3/topics/trap

I would ask you to respond with a clear statement of the function you are trying to integrate ?
The code you shared is a bit of a mishmash...

f <- function(x) { sin(x)^2 + cos(x)^2 }

this is an example where its clear to see that f(x) is a function of x involving square trig terms.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.