MatLab 22BAI1173 Week 5-8
MatLab 22BAI1173 Week 5-8
MatLab 22BAI1173 Week 5-8
Code:
clc
clear
syms x y mkr
f(x,y) = input('Enter the function f(x,y):');
p = diff(f,x);
q = diff(f,y);
[ax, ay] = solve(p,q);
ax = double(ax);
ay=double(ay);
r = diff(p,x);
s = diff(p,y);
t = diff(q,y);
D = r*t-s^2;
figure
fsurf(f);
legstr={'Function Plot'}; % For legend
for i=1:size(ax)
T1=D(ax(i),ay(i));
T2=r(ax(i),ay(i));
T3=f(ax(i),ay(i));
if(double(T1)==0)
sprintf('At (%f,%f) further investigation is required', ax(i),ay(i))
legstr = [legstr, {'Case of Further investigation'}];
mkr ='ko';
elseif (double(T1)<0)
sprintf('The point (%f,%f) is a saddle point', ax(i), ay(i))
legstr = [legstr, {'Saddle Point'}]; % updating Legend
mkr='bv'; % marker
else
if (double(T2) < 0)
sprintf('The maximum value of the function is f(%,%)=%f', ax(i),ay(i),
T3)
legstr = [legstr, {'Maximum value of the function'}];% updating Legend
mkr='g+';% marker
else
sprintf('The minimum value of the function is f(%f,%f)=%f',
ax(i),ay(i), T3)
legstr = [legstr, {'Minimum value of the function'}];% updating Legend
mkr='r*'; % marker
end
end
hold on
plot3(ax(i),ay(i), T3, mkr, 'Linewidth',4);
end
legend (legstr, 'Location', 'Best');
Output:
Q1.
Enter the function f(x,y):
x^4 + y^4 - x^2 - y^2 + 1
ans =
ans =
Code:
clc
clearvars
syms x y L;
F = f + L*g;
gradF = jacobian(F, [x,y]);
[L,x1,y1] = solve (g, gradF(1), gradF (2), 'Real', true);
x1 = double(x1); y1 = double (y1);
title('Constrained Maxima/Minima')
Output:
G =
50
Week 7:
Code:
clc
clear
syms x y z;
f = input('Enter f(x,y): ');
g1 = input('Enter g1(x): ');
g2 = input('Enter g2(x): ');
int(int(f,y,g1,g2),x,a,b)
viewSolid(z,0+0*x+0*y,f,y,g1,g2,x,a,b)
Output:
Q1:
ans = 48
Q2:
Week 8
Code:
clear
clc
syms x y z
xa = input("Enter the lower limit of x please: ");
xb = input("Enter the upper limit of x please ");
ya = input("Enter the lower limit of y please ");
yb = input("Enter the upper limit of y please ");
za = input("Enter the lower limit of z please ");
zb = input("Enter the upper limit of z please ");
I = int(int(int(1+0*z, z, za, zb), y, ya, yb), x, xa, xb) ;
viewSolid (z, za, zb, y, ya, yb, x, xa, xb)
Output:
Q1:
Q2: