0% found this document useful (0 votes)
21 views7 pages

21BLC1109 Assignment-2

This document contains a Matlab code written by Radhesh Kumar Nath with Reg. No. 21BLC1109. The code has two parts: 1) It finds the partial derivative of a 2D function and visualizes it. 2) It finds the maximum, minimum and saddle points of a 2D function. The code takes a 2D function as input, finds its partial derivatives and extreme points, and plots the function along with highlighting the extreme points.
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)
21 views7 pages

21BLC1109 Assignment-2

This document contains a Matlab code written by Radhesh Kumar Nath with Reg. No. 21BLC1109. The code has two parts: 1) It finds the partial derivative of a 2D function and visualizes it. 2) It finds the maximum, minimum and saddle points of a 2D function. The code takes a 2D function as input, finds its partial derivatives and extreme points, and plots the function along with highlighting the extreme points.
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/ 7

Name: Radhesh Kumar Nath

Reg.No: 21BLC1109

AIM: 1.To write Matlab codes to find Partial


derivative of a given function f(x,y) at a
given point (x1,y1) and also visualize it
2. To find the Maximum and Minimum
values (Extreme values) for the given
function f(x,y) using MATLAB
Question:

CODE:
Partial Derivative:
clc

clear all

format compact

syms x y

z = input('Enter the two dimensional function f(x,y): ');


x1 = input('enter the x value at which the derivative has to be evaluated: ');

y1 = input('enter the y value at which the derivative has to be evaluated: ');

z1 = subs(subs(z,x,x1),y,y1)

ezsurf(z,[x1-2 x1+2])

f1 = diff(z,x)

slopex = subs(subs(f1,x,x1),y,y1);

[x2,z2]=meshgrid(x1-2:.25:x1+2,0:0.5:10);

y2=y1*ones(size(x2));

hold on

h1=surf(x2,y2,z2);

set(h1,'FaceColor',[0.7,0.7,0.7],'EdgeColor','none')

t=linspace(-1,1);

x3=x1+t;

y3=y1*ones(size(t));

z3=z1+slopex*t;

line(x3,y3,z3,'color','blue','linewidth',2)

Maxima & Minima:


clc

clear all

format compact

syms x y k T3 real

f = input('Enter the function f(x,y): ');

fx = diff(f,x);

fy = diff(f,y);

[ax ay] = solve(fx,fy);

fxx = diff(fx,x);

D = fxx*diff(fy,y) - diff(fx,y)^2;
r=1;

for k=1:1:size(ax)

if ((imag(ax(k))==0)&&(imag(ay(k))==0))

ptx(r)=ax(k);

pty(r)=ay(k);

r=r+1;

end

end

a1=max(double(ax))

a2=min(double(ax))

b1=max(double(ay))

b2=min(double(ay))

ezsurf(f,[a2-.5,a1+.5,b2-.5,b1+.5])

colormap('summer');

shading interp

hold on

for r1=1:1:(r-1)

T1=subs(subs(D,x,ptx(r1)),y,pty(r1));

T2=subs(subs(fxx,x,ptx(r1)),y,pty(r1));

if (double(T1) == 0)

sprintf('The point (x,y) is (%d,%d) and need further investigation', double(ptx(r1)),double(pty(r1)))

elseif (double(T1) < 0)

[10/11 3:40 pm] Somnath Bera

T3=subs(subs(f,x,ptx(r1)),y,pty(r1))

sprintf('The point (x,y) is (%d,%d) a saddle point', double(ptx(r1)),double(pty(r1)))

plot3(double(ptx(r1)),double(pty(r1)),double(T3),'b.','markersize',30);

else
if (double(T2) < 0)

sprintf('The maximum point(x,y) is (%d, %d)', double(ptx(r1)),double(pty(r1)))

T3=subs(subs(f,x,ptx(r1)),y,pty(r1))

sprintf('The value of the function is %d', double(T3))

plot3(double(ptx(r1)),double(pty(r1)),double(T3),'r+','markersize',30);

else

sprintf('The minimum point(x,y) is (%d, %d)', double(ptx(r1)),double(pty(r1)))

T3=subs(subs(f,x,ptx(r1)),y,pty(r1))

sprintf('The value of the function is %d', double(T3))

plot3(double(ptx(r1)),double(pty(r1)),double(T3),'m*','markersize',30);

end

end

end

• Command window output:

Graph:
• Command window output:

Graph:

You might also like