Experiment-1-B E-Example - 1 Date:13-10-2020: %discretizing The Interval I %finding The Values of F (X) at T Values
Experiment-1-B E-Example - 1 Date:13-10-2020: %discretizing The Interval I %finding The Values of F (X) at T Values
Experiment-1-B E-Example - 1 Date:13-10-2020: %discretizing The Interval I %finding The Values of F (X) at T Values
E-Example – 1
Date:13-10-2020
Question(Aim): ): Using matlab find the local and global maxima and minima for the
function sin|x| on x(2 π ,2 π ).
MATLAB command:
clear
clc
syms x
f(x)=sin(abs(x));
I=[-2*pi,2*pi];
f1(x)=-f(x);
a=I(1);b=I(2);
t=linspace(a,b,10000); %Discretizing the interval I
g=double(f(t)); %Finding the values of f(x) at t values
[lmax_f,loc]=findpeaks(g);
lmax_x=round(t(loc),4);
h=double(f1(t));
[lmin_f,loc]=findpeaks(h);
lmin_x=round(t(loc),4);
disp('Local maximum occur at x=')
disp(lmax_x)
disp('The Local Maximum value(s) of the function are ')
disp(double(f(lmax_x)))
disp('Local minimum occur at x=')
disp(lmin_x)
disp('The Local Minimum value(s) of the function are ')
disp(double(f(lmin_x)))
plot(t,f(t));hold on; %Plotting the function
plot(lmax_x,double(f(lmax_x)),'or');%Pointing the local maxima on the curve of
f(x)
plot(lmin_x,double(f(lmin_x)),'*g');%Pointing the local minima on the curve of
f(x)
hold off
Question(Aim): Using matlab find the local and global maxima and minima for the function
x3-12x-5 on x(4,4).
MATLAB command:
clear
clc
syms x
f(x)=x^3-12*x-5;
I=[-4,4];
f1(x)=-f(x);
a=I(1);b=I(2);
t=linspace(a,b,10000); %Discretizing the interval I
g=double(f(t)); %Finding the values of f(x) at t values
[lmax_f,loc]=findpeaks(g);
lmax_x=round(t(loc),4);
h=double(f1(t));
[lmin_f,loc]=findpeaks(h);
lmin_x=round(t(loc),4);
disp('Local maximum occur at x=')
disp(lmax_x)
disp('The Local Maximum value(s) of the function are ')
disp(double(f(lmax_x)))
disp('Local minimum occur at x=')
disp(lmin_x)
disp('The Local Minimum value(s) of the function are ')
disp(double(f(lmin_x)))
plot(t,f(t));hold on; %Plotting the function
plot(lmax_x,double(f(lmax_x)),'or');%Pointing the local maxima on the curve of
f(x)
plot(lmin_x,double(f(lmin_x)),'*g');%Pointing the local minima on the curve of
f(x)
hold off
E-Record – 2
Date:20-10-2020
Question(Aim):Using matlab find the local and global maxima and minima for the function
xsin 2x on x(5,5)
MATLAB command:
clear
clc
syms x
f(x)=x+sin(2*x);
I=[-5,5];
f1(x)=-f(x);
a=I(1);b=I(2);
t=linspace(a,b,10000); %Discretizing the interval I
g=double(f(t)); %Finding the values of f(x) at t values
[lmax_f,loc]=findpeaks(g);
lmax_x=round(t(loc),4);
h=double(f1(t));
[lmin_f,loc]=findpeaks(h);
lmin_x=round(t(loc),4);
disp('Local maximum occur at x=')
disp(lmax_x)
disp('The Local Maximum value(s) of the function are ')
disp(double(f(lmax_x)))
disp('Local minimum occur at x=')
disp(lmin_x)
disp('The Local Minimum value(s) of the function are ')
disp(double(f(lmin_x)))
plot(t,f(t));hold on; %Plotting the function
plot(lmax_x,double(f(lmax_x)),'or');%Pointing the local maxima on the curve of
f(x)
plot(lmin_x,double(f(lmin_x)),'*g');%Pointing the local minima on the curve of
f(x)
hold off