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

1.write A MATLAB Code To Visualize The Two Dimensional Vector X +X y

The document contains 3 MATLAB code examples to: 1) Visualize the 2D vector xi + x^2yj by generating a quiver plot. 2) Visualize the 3D vector xi + yj + zk by generating a quiver3 plot. 3) Find and visualize the gradient of the function f(x,y)=x^3+y^3 at the point (1,1) using a quiver plot overlaid on a contour plot.

Uploaded by

Katya Pandey
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)
41 views

1.write A MATLAB Code To Visualize The Two Dimensional Vector X +X y

The document contains 3 MATLAB code examples to: 1) Visualize the 2D vector xi + x^2yj by generating a quiver plot. 2) Visualize the 3D vector xi + yj + zk by generating a quiver3 plot. 3) Find and visualize the gradient of the function f(x,y)=x^3+y^3 at the point (1,1) using a quiver plot overlaid on a contour plot.

Uploaded by

Katya Pandey
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/ 4

1.

Write a MATLAB code to visualize the two dimensional


vector x𝒊⃗+x2y𝒋⃗

Code:

clc
clear all
syms x y
F=input('enter the vector as i,j in vector form')
P=inline(vectorize(F(1)),'x','y');
Q=inline(vectorize(F(2)),'x','y');
x=linspace(0,1,10);
y=x;
[X,Y]=meshgrid(x,y);
U=P(X,Y);
V=Q(X,Y);
quiver(X,Y,U,V,1)
axis on
xlabel('x')
ylabel('y')

Input:
enter the vector as i,j in vector form[x x^2*y]

Output:

F =

[ x, x^2*y]
2. Write a MATLAB code to visualize the three dimensional
⃗⃗
vector x𝒊⃗+y𝒋⃗+z𝒌

Code:

clc
clear all
syms x y z
F=input('enter the vector as i,j and k order in vector form');
P=inline(vectorize(F(1)),'x','y','z');
Q=inline(vectorize(F(2)),'x','y','z');
R=inline(vectorize(F(3)),'x','y','z');
x=linspace(-1,1,5);
y=x;
z=x;
[X,Y,Z]=meshgrid(x,y,z);
U=P(X,Y,Z);
V=Q(X,Y,Z);
W=R(X,Y,Z);
quiver3(X,Y,Z,U,V,W,1.5)
axis on
xlabel('x')
ylabel('y')
zlabel('z')

Input:
enter the vector as i,j and k order in vector form [x y z]

Output:

F=

[x y z]
3.Find the value of a gradient of the function
f(x,y)=x3+y3 at the point (1,1,2) and visualize it.

Code:
clc
syms x y
f=input('enter f(x,y):');
f1=diff(f,x)
f2=diff(f,y)
P=inline(vectorize(f(1)),'x','y');
Q=inline(vectorize(f(2)),'x','y');
x=linspace(1,1,2)
y=x
[X,Y]=meshgrid(x,y);
U=P(X,Y);
V=Q(X,Y);
quiver(X,Y,U,V,1)
axis on
xlabel('x')
ylabel('y')
hold
ezcontour(f,[1,1])

Input:
enter f(x,y): x^3+y^3

Output:

f1 =

[ 3*x^2, 0]

f2 =

[ 0, 3*y^2]

x =

1 1

y =

1 1

You might also like