0% found this document useful (0 votes)
13 views3 pages

MATLAB Programs

The document discusses various mathematical concepts including the second derivative test for single and two-variable functions, area between curves, volume under a function, center of mass, and directional derivatives. It provides MATLAB code snippets for each concept, demonstrating how to compute critical points, evaluate maxima and minima, calculate areas and volumes, and find centroids. The document emphasizes the application of calculus in determining properties of functions and regions in a mathematical context.

Uploaded by

apoorva7286
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)
13 views3 pages

MATLAB Programs

The document discusses various mathematical concepts including the second derivative test for single and two-variable functions, area between curves, volume under a function, center of mass, and directional derivatives. It provides MATLAB code snippets for each concept, demonstrating how to compute critical points, evaluate maxima and minima, calculate areas and volumes, and find centroids. The document emphasizes the application of calculus in determining properties of functions and regions in a mathematical context.

Uploaded by

apoorva7286
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/ 3

Second Derivative Test for Single variable functions

syms x
f=(x^4)-4*(x^3)
d1=diff(f,1)
d2=diff(f,2)
crp=solve(d1==0)
cv1=subs(d2,x,crp(1))
cv2=subs(d2,x,crp(2))
cv3=subs(d2,x,crp(3))
if cv1>0
fprintf("Minimum exists at x=%f\n",crp(1))
elseif cv1<0
fprintf("Maximum exists at x=%f\n",crp(2))
else
fprintf("Test fails at x=%f\n",crp(3))
end
if cv2>0
fprintf("Minimum exists at x=%f\n",crp(2))
elseif cv2<0
fprintf("Maximum exists at x=%f\n",crp(2))
else
fprintf("Test fails at x=%f\n",crp(2))
end
if cv3>0
fprintf("Minimum exists at x=%f\n",crp(3))
elseif cv3<0
fprintf("Maximum exists at x=%f\n",crp(3))
else
fprintf("Test fails at x=%f\n",crp(3))
end
m1=subs(f,x,crp(3))
fprintf("Minimum value of f at x=%f\n",m1)

Second derivative test for two variable equation:

syms x y
f = 3*(y^2)-2*(y^3)+3*(x^2)+6*x*y
fx = diff(f,x,1)
fy = diff(f,y,1)
fxx = diff(f,x,2)
fyy = diff(f,y,2)
fxy = diff(fx,y,1)
D = (fxx*fyy)-((fxy)^2)
eq = [fx==0 fy==0]
var = [x y]
[x1 y1] = solve(eq,var)
crp = [x1(:) y1(:)]
for i = 1:size(crp, 1)
x_v = crp(i, 1);
y_v = crp(i, 2);
fxx_v = subs(fxx, [x, y], [x_v, y_v]);
fyy_v = subs(fyy, [x, y], [x_v, y_v]);
fxy_v = subs(fxy, [x, y], [x_v, y_v]);
D_v = (fxx_v*fyy_v)-((fxy_v)^2)
if D_v > 0
if fxx_v > 0
fprintf('(%f,%f) gives minimum of \n', x_v, y_v);
else
fprintf('(%f,%f) gives maximum of \n', x_v, y_v);
end
elseif D_v < 0
fprintf('(%f,%f) is a saddle point \n', x_v, y_v);
else
fprintf('(%f,%f) is inconclusive \n', x_v, y_v);
end
end

Area between two curves:


syms x
f=4*(x^2);
g=(6*x)-2;
v=solve(f==g);
a=max(v);
b=min(v);
i=int(f-g,b,a);
fprintf("Area between f and g is i=%f\n",abs(i))

Volume covered by the function:

syms x y
f=x+y
y_lower=0
y_upper=sin(x)
x_lower=0
x_upper=pi
volume=int(int(f,y,y_lower,y_upper),x,x_lower,x_upper)
fprintf("Volume bounded by the function is=%f\n",volume)

Center of mass:

syms x y
x_lower = y^2;
x_upper = 2*y - y^2;
y_inter = solve(y^2 == 2*y - y^2, y);
y_min=min(y_inter)
y_max=max(y_inter)
area=int(int(1, x, x_lower, x_upper), y, y_min, y_max);
Mx = int(int(x, x, x_lower, x_upper), y, y_min, y_max);
My = int(int(y, x, x_lower, x_upper), y, y_min, y_max);
x_centroid = Mx / area;
y_centroid = My / area;
fprintf("Area of the region=%f\n",area)
fprintf("Center of mass of x is =%f\n",Mx)
fprintf("Center of mass of y is =%f\n",My)
Directional Derivatives:

syms x y z
f = x^2 + 5*x*y + y^2;
grad_f = gradient(f, [x, y, z]);
point = [1, 2, 3];
grad_point = subs(grad_f, [x, y, z], point)
u = [2, 1, -4];
u_norm = u / norm(u);
directional_derivative = dot(grad_point, u_norm);
fprintf("Directional derivative of given point is equal to =%f\n",u_norm)

You might also like