1.write A MATLAB Code To Visualize The Two Dimensional Vector X +X y
1.write A MATLAB Code To Visualize The Two Dimensional Vector X +X y
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