Using trapz function to provide answers using loop
Show older comments
Hey,
I am trying to use the trapz function in a loop:
y_approx = zeros ([21 1]);
for i = 1:length(x)
y_approx = trapz(x(i),y)
end
It is providing me the 21 answers but they are incorrect. I think it is using the 21 y for each iteration of x. 21 y values for 1 x value, 21 y values for 2 x values etc. How do I alter the code to make it use the same number of y values as x values?
Accepted Answer
More 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!