0% found this document useful (0 votes)
8 views

Matlab 5

Uploaded by

Babzch Kan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Matlab 5

Uploaded by

Babzch Kan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Fawaz Khan

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:

In this problem, we successfully visualized a two-variable function f(x,y)

and its tangent planes at a given point using MATLAB. By computing the

partial derivatives, we were able to derive the slopes of the tangent

planes along the x and y directions. The use of MATLAB's symbolic

capabilities allowed us to compute these derivatives analytically, and its

powerful plotting functions enabled us to visualize both the original

function and the tangent planes effectively. It allows us to work with

complex mathematical expressions and easily translate them into

numerical computations and graphical representations. This makes

MATLAB an indispensable tool for engineers and scientists working on

multivariable calculus, differential equations, and related fields.

You might also like