Many students ask me how do I do this or that in MATLAB. So I thought why not have a small series of my next few blogs do that. In this blog, I show you how to differentiate a function.
The MATLAB program link is here.
The HTML version of the MATLAB program is here.
%% HOW DO I DO THAT IN MATLAB SERIES?
% In this series, I am answering questions that students have asked
% me about MATLAB. Most of the questions relate to a mathematical
% How do I differentiate a function?
% Language : Matlab 2008a
% Authors : Autar Kaw
% Mfile available at
% Last Revised : March 21, 2009
% Abstract: This program shows you how to differentiate a given function
disp(‘ This program shows you how to differentiate’)
disp(‘ a given function and then find its value’)
disp(‘ at a given point’)
disp(‘ Autar K Kaw of https://autarkaw.wordpress.com’)
disp(‘ March 21, 2009’)
% Differentiate 7 exp(3*x) once and find the value of the
% first derivative at x=0.5
% Define x as a symbol
% Defining the function to be differentiated
% Defining the point where you want to find the derivative
%% DISPLAYING INPUTS
func=[‘ The function is to be differentiated is ‘ char(y)];
fprintf(‘ Value of x where you want to find the derivative, x= %g’,xx)
%% THE CODE
% Finding the derivative using the diff command
% Argument 1 is the function to be differentiated
% Argument 2 is the variable with respect to which the
% function is to be differentiated – the independent variable
% Argument 3 is the order of derivative
% subs command substitues the value of x
%% DISPLAYING OUTPUTS
derivative_func=[‘ The derivative of function ‘ char(y) ‘ is ‘ char(dydx)];
fprintf(‘ Value of dydx at x=%g is =%g’,xx,dydx_val)
This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, and the YouTube video lectures available at http://nm.mathforcollege.com/videos and http://www.youtube.com/numericalmethodsguy
Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.
8 thoughts on “How do I differentiate in MATLAB?”
I enough understand if so many students ask how to get derivative a function using tool box of matlab, because matlab script for the differential commonly included or available in applications tool box. So, sometime students rather confuse when they would calculate even for drawing the graph of derivatif a function respect to it’s independent variable. I believe the scripts of finding derivative a function examplized at above are not only useful for all students at USF but also for my students at Physics Department of ITS Surabaya. Thanks for the above explanation.
Thank you for the posting. It is quite useful to get the derivative using this code. But I wonder is it suitable for matrix differentiation as well? If not, is there any other function that I can use to get matrix differentiation?
hi.i want to know how i defrentiate and plot cos2x in matlab
email me your complete problem statement and code if you have written. I need it
The links are for the program are in the blog!
what a great tutorial. it really saved my time. thanks!
but this syms is not supporting to transfer function (s=tf(‘s’)) i wanted find derivative of transfer function with respect to s
i want df at s=0.1