Session3 2
Session3 2
syms x
y = input('Enter the function f in terms of x: ');
% Example: Try the function y = x^2 - 2*x;
hold off;
Plot the Function and its Derivatives
• To plot the function and its derivatives in MATLAB, you can use the ‘ezplot’, ‘plot’, or ‘fplot’ functions.
• Here are some examples code to plot the function and its rst and second derivatives:
%% Example 1
%% Example 3
clear
clc
syms x
% Input a function "f(x)" and the range of "x"
f= input('Enter the function f(x):'); % e.g. f(x) = x^3 +
5*x^2 + 3*x + 1
D=input('Enter the range of x:'); % e.g. D = [0, 5];