24bce2355 Matlab Da1
24bce2355 Matlab Da1
AIM:
.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:
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.
OUTPUT:
ANSWER-2(24BCE2355)
AIM:
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:
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);
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:
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
-0.4855 1.9037
2.7871 3.9204