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://numericalmethods.eng.usf.edu, the textbook on Numerical Methods with Applications available from the lulu storefront, and the YouTube video lectures available at http://numericalmethods.eng.usf.edu/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.