0% found this document useful (0 votes)
17 views8 pages

24bce2355 Matlab Da1

The document outlines various MATLAB tasks including plotting functions, evaluating limits, finding derivatives, and analyzing maxima and minima. It provides specific code snippets and outputs for each task, such as plotting a function with a tangent line, evaluating limits of expressions, and identifying local extrema. Each section includes the aim, major formulas used, and the corresponding MATLAB code along with the results.

Uploaded by

abhijaysharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

24bce2355 Matlab Da1

The document outlines various MATLAB tasks including plotting functions, evaluating limits, finding derivatives, and analyzing maxima and minima. It provides specific code snippets and outputs for each task, such as plotting a function with a tangent line, evaluating limits of expressions, and identifying local extrema. Each section includes the aim, major formulas used, and the corresponding MATLAB code along with the results.

Uploaded by

abhijaysharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ANSWER-1 (24BCE2355)

AIM:

Plot the graph of the function f(x)=4sinx+e^x+3x^10 -20 in the interval[-5pi,10pi]

.Indicate the x-label, y-label, title of the graph. Set the thickness of the line as 3 pt. On the same graph,
superimpose the curve g(x)=x^2+cos3x with a different color.

MAJOR FORMULA:

1)plot(x,y)- plots y vector against x vector

2)hold on and hold off functions help to superimpose graphs by using two plots.

3) xlabel, ylabel and title functions are used to modify and add elements to the graph.

MATLAB CODE AND OUTPUT IS AS FOLLOWS:


syms x
x=linspace(-5*pi,10*pi,10000)
y=4*sin(x)+exp(x)+3*x.^(10)-20
dy=x.^2+cos(3*x)
plot(x,y,'r','LineWidth',3)
hold on
plot(x,dy,'b','LineWidth',3)
hold off
xlabel('xlabel')
ylabel('ylabel')
title('title')

OUTPUT:
ANSWER-2(24BCE2355)

AIM:

To evaluate the following commands using matlab

MAJOR FORMULAE:

1)limit(y,x,1): the first argument is the function whose limit is to be calculated the second argument is the
variable that approaches to the third argument.

2) diff(y,x,z): the first argument is the function, the second argument is the variable with respect to which the
function is differentiated and the third argument is the order of derivative

CODE:
syms x
%calculating limit(a)
f(x)=(x.^2+exp(x))/(cos(x)+sin(x));
A=limit(f(x),x,1);
B=double(A)
%calculating second derivative(b)
g(x)=((x.^2+exp(2*x)*cos(3*x))).^2/(exp(2*x)+(x.^2)*sin(4*x)).^2;
h(x)=diff(g(x),x,2);
c=subs(h(x),x,1);
e=double(c)

OUTPUT:

B=

2.6909

e=

-19.3474
ANSWER-3(24BCE2355)

AIM:

To find and show the tangent to y^3=e^(3x)+x at x=2 graphically.

MAJOR FORMULAE:

1) subs(y,x,a): The first argument is the function, the second argument is the variable which approaches to
the third argument(value).
2) matlabFunction(y): converts the symbolic function ‘y’ to numeric function so that values can be
susbtitued.
3) plot(x,y): this function plots y vector versus x vector

CODE:
clear all
clc
syms x
y = (exp(3*x) + x)^(1/3);

%value of the function at x = 2


A = subs(y, x, 2);
AA = double(A);

% getting the slope of the tangent at x=2


a = diff(y, x, 1);
b = subs(a, x, 2);
B = double(b);

% Tangent equation: y - y1 = m(x - x1)


tangent = AA + B * (x - 2)

x_vals = linspace(-4, 4, 1000);


% converting y and tangent into numeric functions
y_func = matlabFunction(y);
tangent_func = matlabFunction(tangent);

y_vals = y_func(x_vals);
tangent_vals = tangent_func(x_vals);
plot(x_vals, y_vals, 'b', 'LineWidth', 1);
hold on
plot(x_vals, tangent_vals, 'r', 'LineWidth', 1);
hold off
xlabel('x');
ylabel('y');
title('Function and its Tangent Line at x = 2');
legend('y = (exp(3x) + x)^{1/3}', 'Tangent at x = 2');
grid on
OUTPUT:

tangent =

(8298806464964687*x)/1125899906842624 - 8264550294835505/1125899906842624
ANSWER-4(24BCE2355)

AIM:

MAJOR FORMULAE:

1) piecewise(<function>): helps to plot a piecewise function.


2) fplot(f,[a,b]): plots a function f with the independent variable having domain [a,b].

CODE:
%forming the piecewise function
syms x
f = piecewise(x < 0, -x, 0 <= x & x <= 1, x^2, x > 1, 1);
%Plotting the function
fplot(f, [-3, 3], 'LineWidth', 2)
xlabel('x')
ylabel('f(x)')
title('Plot of the required function is')
grid on

OUTPUT:
ANSWER-5(24BCE2355)

AIM: To find the local and global maxima and minima for the following function f(x)=x^2+cos(2x)-2sin(3x) on the
interval (-5,5) and form its graph.

MAJOR FORMULAE:

1) findpeaks: the function returns the value of peaks and at what value of the vector they occur.
2) plot(x,y): plots vector y versus x

CODE:
syms x
f(x)=x.^2+cos(2*x)-2*sin(3*x);
I=[-5,5];
f1(x)=-f(x);
a=I(1);b=I(2);
t=linspace(a,b,10000); I
g=double(f(t));
[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;
plot(lmax_x,double(f(lmax_x)),'or');
plot(lmin_x,double(f(lmin_x)),'*g');
hold off
OUTPUT:

I=

-5 5

Local maximum occur at x=

-0.4855 1.9037

The Local Maximum value(s) of the function are

2.7871 3.9204

Local minimum occur at x=

-1.4366 0.5616 2.1127


The Local Minimum value(s) of the function are

-0.7405 -1.2388 3.8858

You might also like