Matlab2
Matlab2
Assignment 1
Q partial differentiation of the eq. f= e^(x2+y2)
syms x y
f=exp(x.^2+y.^2)
P=diff(f,x)
R=diff(f,y)
P1=diff(P,x)
R1=diff(R,y)
Q1=subs(P1, {x,y},{0.5.*pi,0.5.*pi})
Q2=subs(R1, {x,y},{0.5.*pi,0.5.*pi})
if (Q1==Q2)
display('Mixed Partial Derivatives are Equal')
end
if (Q1 ~= Q2)
display('Mixed partial Derivatives are not equal')
end
output
>> partialderivative Q1 =
f= 2*exp(pi^2/2) + pi^2*exp(pi^2/2)
exp(x^2 + y^2) Q2 =
P= 2*exp(pi^2/2) + pi^2*exp(pi^2/2)
2*x*exp(x^2 + y^2) Mixed Partial Derivatives are Equal
R= >>
2*y*exp(x^2 + y^2)
P1 =
2*exp(x^2 + y^2) + 4*x^2*exp(x^2 + y^2)
R1 =
2*exp(x^2 + y^2) + 4*y^2*exp(x^2 + y^2)
Assignment 2
A = [1 2 3 ; 4 5 6 ; 7 8 9 ]
m = size (A)
n = min (m)
R=rank(A)
D = det(A)
if (D~=0)
B = inv(A)
end
OUTPUT
>> AASSIN6
A= B=
1 2 3 1.0e+16 *
4 5 6
7 8 9 -0.4504 0.9007 -0.4504
m= 0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504
3 3
n= >>
3
R=
2
D=
6.6613e-16
ASSIGNMENT 3
q. x+y = 4
y-z = 1 Comment upon the consistency/inconsistency by evaluating the rank.
2x+y+4z = 7
A = [1 1 0; 0 1 -1; 2 1 4]
B = [4; 1; 7]
A_bar = [1 1 0 4; 0 1 -1 1; 2 1 4 7]
rank_A = rank(A);
rank_A_bar = rank(A_bar);
if rank_A == rank_A_bar
disp('The system is consistent.');
if rank_A == size(A,2)
disp('The system has a unique solution.');
X = A\B;
disp('Solution:');
disp(X);
else
disp('The system has infinitely many solutions.');
end
else
disp('The system is inconsistent.');
end
output
A= A_bar =
1 1 0 1 1 0 4
0 1 -1 0 1 -1 1
2 1 4 2 1 4 7
B= The system is consistent.
4 The system has a unique solution.
1 Solution:
7 3
1
0
ASSIGNMENT 3
. x+2y-z = 10
-x+y+2z = 2 Comment upon the consistency/inconsistency by evaluating the rank.
2x+y-3z = 8
A = [1 2 -1; -1 1 2; 2 1 -3]
B = [10;2;8]
A_bar = [1 2 -1 10; -1 1 2 2; 2 1 -3 8]
rank_A = rank(A);
rank_A_bar = rank(A_bar);
if rank_A == rank_A_bar
disp('The system is consistent.');
if rank_A == size(A,2)
disp('The system has a unique solution.');
X = A\B;
disp('Solution:');
disp(X);
else
disp('The system has infinitely many solutions.');
end
else
disp('The system is inconsistent.');
end
output
A= A_bar =
1 2 -1 1 2 -1 10
-1 1 2 -1 1 2 2
2 1 -3 2 1 -3 8
B=
10 The system is consistent.
2 The system has infinitely many solutions.
8
ASSIGNMENT 4
x+y+z = 1
2x+y+2z = 2 Comment upon the consistency/inconsistency by evaluating the rank.
3x+2y+3z = 5
code
A = [1 1 1; 2 1 2; 3 2 3]
B = [1;2;5]
A_bar = [1 1 1 1; 2 1 2 2; 3 2 3 5]
rank_A = rank(A);
rank_A_bar = rank(A_bar);
if rank_A == rank_A_bar
disp('The system is consistent.');
if rank_A == size(A,2)
disp('The system has a unique solution.');
X = A\B;
disp('Solution:');
disp(X);
else
disp('The system has infinitely many solutions.');
end
else
disp('The system is inconsistent.');
end
output
A= A_bar =
1 1 1
2 1 2 1 1 1 1
3 2 3 2 1 2 2
B= 3 2 3 5
f=
x^2 + y^2 + z^2
F=
[x*y, y*z, x*z]
grad_f =
2*x
2*y
2*z
div_F =
x+y+z
curl_F =
-y
-z
-x
grad_f =
2*x
2*y
2*z
div_F =
x+y+z
curl_F =
-y
-z
-x
ASSIGNMENT
Q F= x2yî-2xzĵ+2yzz Find the curl curl F.
syms x y z
output
F=
curl_F =
2*x + 2*z
0
- x^2 - 2*z
curl_curlF =
0
2*x + 2
0
ASSIGNMENT
Q F= grad(x3+y3+z3-3xyz) Find the div F, curl F.
syms x y z
f = x^3+y^3+z^3-3*x*y*z
F=gradient(f,[x y z])
div_F=divergence(F,[x y z])
curl_F=curl(F,[x y z])
output
f=
x^3 - 3*x*y*z + y^3 + z^3
F=
3*x^2 - 3*y*z
3*y^2 - 3*x*z
3*z^2 - 3*x*y
div_F =
curl_F =
0
0
0
ASSIGNMENT
f=x2y+2xy+z2 Show that curl grad f=0.
syms x y z
f = x*x*y+2*x*y+z*z;
curl_f=curl(grad_f,[x y z])
output
grad_f =
2*y + 2*x*y
x^2 + 2*x
2*z
curl_f =
0
0
0
ASSIGNMENT
Q Find the Directional derivative of x*y + y*z + z*x at (1, 2, 0) in the direction of 1, 2, 2.
syms x y z;
theta = x*y + y*z + z*x;
point = [1, 2, 0];
direction = [1, 2, 2];
grad_theta = gradient(theta, [x, y, z]);
grad_theta_at_point = subs(grad_theta, [x, y, z], point);
direction_unit = direction / norm(direction);
D_theta = dot(grad_theta_at_point, direction_unit);
fprintf('Directional derivative for Problem 1: %f\n', double(D_theta));
output
Directional derivative for Problem 1: 3.333333
ASSIGNMENT
Q Find the Directional derivative 2*x^2 + 3*y^2 + z^2 at (2, 1, 3) in the direction of 1, 0, -2.
syms x y z;
f = 2*x^2 + 3*y^2 + z^2;
point = [2, 1, 3];
direction = [1, 0, -2];
grad_f = gradient(f, [x, y, z]);
grad_f_at_point = subs(grad_f, [x, y, z], point);
direction_unit = direction / norm(direction);
D_f = dot(grad_f_at_point, direction_unit);
fprintf('Directional derivative for Problem 3: %f\n', double(D_f));
output
Directional derivative for Problem 3: -1.788854
ASSIGNMENT
Q Find the Directional derivative 2*x^2 + 3*y^2 + z^2 at (2, 1, 3) in the direction of 1, 0, -2.