trapezoidal rule with user define function
Show older comments
I am new in matlab.i want to create user define function for trapezoidal rule in which i want to take input arguments a,b,n, and the intervals values.I have seached alot but all function taking a function in argument not interval values..
3 Comments
Geoff Hayes
on 3 Jul 2020
John - please describe in detail the function that you want to create. What should the function signature be? Are you using trapz or implementing your own function for the trapezoidal rule? Are the input arguments just a, b, and n where presumably n will be used to determine the number of elements that you will take from the interval [a,b]. What does all function taking a function in argument not interval values mean? Which function takes a function as an input (?) argument?
John Jessy
on 3 Jul 2020
John D'Errico
on 3 Jul 2020
Edited: John D'Errico
on 3 Jul 2020
But this seems not to make any sense at all.
You want to pass in the actual vectors x and y? If so, then it makes no sense to also pass in a, b, and n. If you already have x as a vector, then x is given. If you already have y as a vector, then f as a function is irrelevant.
Are you asking how to write the trapezoidal rule for VECTORS x and y as already given?
I would note there is absolutely no reason to do this, since you already have the function trapz which does exactly that. trapz is part of MATLAB already. So unless this is your homework assignment, then there is no need.
So what would the function header look like? Start out one line at a time.
Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!