2018/04/12

Matlab: Basic Differentiation and Integration with the syms symbolic variable

To perform basic calculus calculations with Matlab, declare symbolic variables with syms command:

>> syms x;
>> y = 3*x^3+2*x^2-4*x+5;

Hence y = 3x3+2x2-4x+5.

For differentiation, the derivative of y is y' = diff(y):

>> y_prime = diff(y)

y_prime =

9*x^2 + 4*x - 4

Hence y' = dy/dx = 9x2+4x-4.

For integration, the integral of y is ∫ y dy = int(y):

>> y_integral = int(y)

y_integral =

(3*x^4)/4 + (2*x^3)/3 - 2*x^2 + 5*x

Consequently, ∫ y dy = (3x4)/4 + (2x3)/3 - 2x2 + 5x + c.

沒有留言:

張貼留言