Matlab 5
Matlab 5
Reg.no:24BLC1355
MATLAB ASSIGNMENT-5
AIM:
Plot any two-variable function f(x,y). Get a point as an input from the
user. Find the slopes of the tangents to the function f(x,y) at the given
point along x any y directions. Visualize both these tangent planes.
(Arrange the graphs of the function, the tangent planes along x and y
directions using subplot command).
PROGRAM:
clc
clear all
syms x y;
z = input('Enter the two dimensional function f(x,y): ');
x1 = input('Enter the x-coordinate of the point: ');
y1 = input('Enter the y-coordinate of the point: ');
f1 = diff(z, x);
f2 = diff(z, y);
z1 = double(subs(z, [x, y], [x1, y1]));
slopex = double(subs(f1, [x, y], [x1, y1]));
slopey = double(subs(f2, [x, y], [x1, y1]));
tangent_plane = z1 + slopex * (x - x1) + slopey * (y - y1);
[x2, y2] = meshgrid(linspace(x1-5, x1+5, 100), linspace(y1-5,
y1+5, 100));
z2 = double(subs(z, {x, y}, {x2, y2}));
tangent_vals = double(subs(tangent_plane, {x, y}, {x2, y2}));
tangent_x = z1 + slopex * (x2 - x1);
tangent_y = z1 + slopey * (y2 - y1);
figure;
subplot(1, 3, 1);
surf(x2, y2, z2);
title('Original function f(x, y)');
xlabel('x'); ylabel('y'); zlabel('z');
hold on;
plot3(x1, y1, z1, 'ro', 'MarkerSize', 10, 'MarkerFaceColor',
'r');
hold off;
subplot(1, 3, 2);
surf(x2, y2, tangent_x);
title('Tangent plane along x direction');
xlabel('x'); ylabel('y'); zlabel('z');
hold on;
plot3(x1, y1, z1, 'ro', 'MarkerSize', 10, 'MarkerFaceColor',
'r');
hold off;
subplot(1, 3, 3);
surf(x2, y2, tangent_y);
title('Tangent plane along y direction');
xlabel('x'); ylabel('y'); zlabel('z');
hold on;
plot3(x1, y1, z1, 'ro', 'MarkerSize', 10, 'MarkerFaceColor',
'r');
hold off;
OUTPUT:
CONCLUSION:
and its tangent planes at a given point using MATLAB. By computing the