EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials Matlab Tutorial MATLAB Derivative

MATLAB Derivative

Priya Pedamkar
Article byPriya Pedamkar

Updated February 27, 2023

MATLAB Derivative

Introduction to MATLAB Derivative

MATLAB is a programming environment that is interactive and is used in scientific computing. It is extensively used in a lot of technical fields where problem-solving, data analysis, algorithm development, and experimentation is required. The discipline-specific software is extensively written using MATLAB. MATLAB provides us the ability to perform numerous mathematical operations, In this topic, we are going to learn about MATLAB Derivative.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

How does MATLAB Derivative work?

Differentiation is a calculus tool that calculates small changes in a function. Differentiation or derivative is the rate of change of a function w.r.t. some variable. It calculates how sensitive our output is concerning any change in our input.

Mathematically, it can be represented as f(x)/dx, where dx represents the change in the value of function f (x), concerning the variable x.

Let us now understand how derivative works in MATLAB.

Syntax of derivative:

  • diff (f)
  • diff (f, n)
  • diff (f, var)
  • diff (f, var, n)

Examples of MATLAB Derivative

Here are the following examples mention below

Example #1 – diff (f)

This function will differentiate ‘f’ with the variable x

Here is an example where we compute the differentiation of a function using diff (f):

Lets us take a polynomial function defined as:

x ^ 4 + 3 x ^ 3 + 4 x ^ 2 + 5 x + 1

Syntax

df = diff (f, x)

The function diff will return derivative value of the functionx ^ 4 + 3 x ^ 3 + 4 x ^ 2 + 5 x + 1:

4x^3 + 9x^2 + 8x + 5

Input:

syms f(x)
f(x) = x ^ 4 + 3*x ^ 3 + 4*x ^ 2 + 5*x + 1
df = diff (f, x)

Output:

matlab derivative output 1

Example #2 – diff (f, n)

This function is used to calculate the nth derivative of the input function. ‘n’ here is passed as an argument.

Here is an example where we compute ‘nth’ derivative of a function using diff (f, n):

Lets us take another polynomial function defined as:

3 x ^ 3 + 2 x ^ 2 + 7 x + 5

For our example, we will calculate the 2nd derivative.

Mathematically, our output should be:

18x + 4

Input:

syms f(x)
f(x) = 3*x^3 + 2*x^2 + 7*x + 5
df = diff (f, 2)

Output:

matlab derivative output 2

As we can see, diff (f, n) has calculated the 2nd derivative of our input function.

Example #3 – diff (f, var)

This function will find the derivative of ‘f’ w.r.t the variable in the argument.

Here is an example where we compute differentiation of a function using diff (f, var):

Lets us take a sine function defined as:

Sin(x*t^2)

For our example, we will calculate the derivative w.r.t ‘t’

Mathematically, our output should be:

2txcos(t^2x)

Input:

syms x t
diff(sin(x*t^2),t)

Output:

output 3

As we can see, the derivative is calculated w.r.t.  ‘t’ as expected by us.

[Notice that we have passed ‘t’ as an argument. Diff function will now take the derivative w.r.t ‘t’]

Example #4 – diff (f, var, n)

This function will calculate the ‘nth’ derivative of the input function w.r.t the variable we pass as an argument.

Below is the example where we calculate the derivative of a function using diff (f, var, n):

Lets us take a sine function defined as:

Sin(x*t^4)

For our example, we will calculate the ‘2nd’ derivative w.r.t ‘t’

Mathematically, our output should be:

12t^2xcos(t^4x) - 16t^6x^2sin(t^4x)

Input:

syms x t
diff(sin(x*t^4),t,2)

Output:

output 4

As we can see, we have got the 2nd derivative of our input function w.r.t ‘t’, as expected.

[Notice the arguments ‘t’ and ‘2’, for derivative w.r.t and nth derivative respectively]

Conclusion

‘diff’ function is used in MATLAB to calculate the differentiation or derivative of a function. We can calculate the derivative w.r.t the default variable or the variable we pass as an argument. Also, the degree of differentiation or derivative can be controlled using the argument.

Recommended Articles

This is a guide to MATLAB Derivative. Here we discuss how does MATLAB Derivative work along with appropriate syntax and respective examples. You may also look at the following articles to learn more –

  1. Matlab Plot Circle
  2. Matlab stem()
  3. Linear Fit Matlab
  4. Covariance in Matlab
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
62+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests
 11+ Hours of HD Videos
5 Courses
3 Mock Tests & Quizzes
  Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more