I tried to write a code for a rectangle method(integral). Actually i saw same problem with other numerical methods too.
My problem is occur when i write a function like f = sin(x), sin(x^2) or x + sin(x^2) etc. (and i wrote a=0 and b = pi)
This code solves equations which doesn't have a trigonometric parameters.
How can i edit my code?
f =@(x) x^2;a = 1;b = 4;n = 2;h = (b-a)/n;x(1) = f(1);for j = 1:(n) x(j+1) = x(1) + j*h; c(j) = (x(j+1) + x(j)) / 2;endfor i = 1:n s(i) = h * f(c(i));endfx = sum(s);fprintf('\n f(x) = %f',fx);
Best Answer