MATLAB: How to calculate a derivative derivative and integration can some one guide me how to calculate a derivative and integration in matlab . can you please give a little example. Best Answer Symbolicallysyms x realf = 1/xint(f,1,2) % integrationans =log(2)diff(f) %differentiationans = -1/x^2[edit - amplification]syms x a b real positivef = 1/xf =1/xint(f) % without limitsans =log(x)int(f,a,b) % with limitsans =log(b) - log(a)fn = matlabFunction(f) % convert symbolic to anonymous functionfn = @(x)1./xquadgk(fn,1,2) % integrate numericallyans = 0.6931log(2) % previous result from symbolic integrationans = 0.6931 (fn(2+1e-6)-fn(2))/1e-6 %numerical derivative at fn(2)ans = -0.2500 subs(diff(f),2) %substitute 2 into symbolic result previously obtainedans = -0.2500 Related SolutionsMATLAB: Integration in MATLAB with symbolic integration limits syms xy=x^2f=int(y,1,x) % integration between 1 and x MATLAB: Derivative at various points in symbolic math toolbox A = [1 2 4 6];syms xf(x) = x^2sol = f(A)gives:f(x) = x^2 sol = [ 1, 4, 16, 36] Related QuestionThe answer this trigonometric integration example is wrong despite attempts to remedy it. Anyone knows whyEvaluating a symbolic heaviside function using subs at points where disconuities are located
Best Answer