MATLAB offset when plotting integration of sin -
i have question, because work many functions, have trouble when trying plot integral of sine (i using matlab 2010):
clear close clc x = linspace(-10, 10, 100); f = @(x) sin(x); = arrayfun(@(x) quad(f, 0, x), x); plot(x, f(x),'r', x, i, 'b')
i expect having -cos(x), instead offset of 1, why happening? how should fix problem?
the fundamental theorem of calculus says indefinite integral of nice function f(x) equal function's antiderivative f(x), unique up-to additive constant. further, definite integral has form:
in form, constant of integration cancel out, , integral equal desired antiderivative only if lower bound evaluation vanishes. however, -cos(0)
not vanish , has value of -1
. in order calculate desired antiderivative f(x), lower bound evaluation should added right-hand side.
plot(x, f(x),'r', x, i+ (-cos(0)), 'b');
this equivalent of assigning initial value solution of odes la ode45
.
Comments
Post a Comment