0% found this document useful (0 votes)
9 views7 pages

Matlab 3 Kowshik

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

Matlab 3 Kowshik

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

MATLAB-3

M.Kowshik

JUUG24BTECH14294

BTECH ECE

EXERCISE PROBLEMS 1

syms x y
f = input('Enter the function f(x, y) for Problem 1: ');
df_dx = diff(f, x);
df_dy = diff(f, y);
d2f_dx2 = diff(f, x, 2);
d2f_dy2 = diff(f, y, 2);
d2f_dxdy = diff(diff(f, x), y);
fprintf('Problem 1:\n');

Problem 1:

pretty(df_dx)

2 2
3 x - 30 x + 3 y + 72

pretty(df_dy)

6 x y - 30 y

pretty(d2f_dx2)

6 x - 30

pretty(d2f_dy2)

6 x - 30

pretty(d2f_dxdy)

6 y

f = input('Enter the function f(x, y) for Problem 2: ');


df_dx = diff(f, x);
df_dy = diff(f, y);
fprintf('\nProblem 2:\n');

Problem 2:

1
pretty(df_dx)

2
3 x - 4 x + y

pretty(df_dy)

2
3 y - 8 y + x

syms z
f = input('Enter the function f(x, y, z) for Problem 3: ');
df_dx = diff(f, x);
df_dy = diff(f, y);
df_dz = diff(f, z);
fprintf('\nProblem 3:\n');

Problem 3:

pretty(df_dx)

2 2
3 x - 4 x - 8 y + z y

pretty(df_dy)

2
3 y - 16 x y + x z

pretty(df_dz)

2
3 z + x y

syms t
x_t = exp(t);
y_t = t^2;
u = input('Enter the function u in terms of x and y for Problem 4: ');
du_dt = diff(subs(u, {x, y}, {x_t, y_t}), t);
fprintf('\nProblem 4:\n');

Problem 4:

pretty(du_dt)

/ exp(t) \ / exp(t) 2 exp(t) \


cos| ------ | | ------ - -------- |
| 2 | | 2 3 |
\ t / \ t t /

2
x_t = exp(2*t);
y_t = exp(2*t) * cos(3*t);
z_t = exp(2*t) * sin(3*t);
u = input('Enter the function u in terms of x, y, z for Problem 5: ');
du_dt = diff(subs(u, {x, y, z}, {x_t, y_t, z_t}), t);
fprintf('\nProblem 5:\n');

Problem 5:

pretty(du_dt)

2 2
exp(4 t) 4 + cos(3 t) exp(4 t) 4 + sin(3 t) exp(4 t) 4

syms u v
x = input('Enter the function x(u, v) for Problem 6: ');
y = input('Enter the function y(u, v) for Problem 6: ');
J = jacobian([x, y], [u, v]);
fprintf('\nProblem 6:\n');

Problem 6:

pretty(J)

/ v + 1, u \
| |
\ v, u + 1 /

x = input('Enter the function x(u, v) for Problem 7: ');


y = input('Enter the function y(u, v) for Problem 7: ');
J = jacobian([x, y], [u, v]);
fprintf('\nProblem 7:\n');

Problem 7:

pretty(J)

/ 2 \
| 2 u u |
| ---, - -- |
| v 2 |
| v |

3
| |
| 2 |
| v 2 v |
| - --, --- |
| 2 u |
\ u /

clc
syms x y
f=input('Enter the function f(x,y):');
p= diff(f,x);
q=diff(f,y);
[ax,ay]=solve(p,q);
ax=double(ax);ay=double(ay);
r=diff(p,x);
s=diff(p,y);
t =diff(q,y);
D=r*t-s^2;
for i=1: size(ax)
T1=subs(D,{x,y},{ax(i),ay(i)});
T2=subs(r,{x,y},{ax(i),ay(i)});
T3=subs(f,{x,y},{ax(i),ay(i)});
if (double(T1) == 0)
sprintf('At (%f,%f) further investigation is required', ax(i),ay(i))
elseif (double(T1) < 0)
sprintf('The point (%f,%f) is a saddle point', ax(i),ay(i))
else
if (double(T2) < 0)
sprintf('The maximum value of the function is f(%f,%f)=%f',
ax(i),ay(i),double(T3))
else
sprintf('The minimum value of the function is f(%f,%f)=%f',
ax(i),ay(i),double(T3))
end
end
end

Warning: Colon operands must be real scalars. This warning will become an error in a future release.
ans =
'The maximum value of the function is f(0.000000,0.000000)=1.000000'
ans =
'The minimum value of the function is f(-0.707107,-0.707107)=0.500000'
ans =
'The minimum value of the function is f(0.707107,-0.707107)=0.500000'
ans =
'The minimum value of the function is f(-0.707107,0.707107)=0.500000'
ans =
'The minimum value of the function is f(0.707107,0.707107)=0.500000'
ans =
'The point (-0.707107,0.000000) is a saddle point'
ans =
'The point (0.707107,0.000000) is a saddle point'

4
ans =
'The point (0.000000,-0.707107) is a saddle point'
ans =
'The point (0.000000,0.707107) is a saddle point'

EXERCISE PROBLEMS 2

syms t
x = 1 - t^3;
y = 1 + t^2;
z = 2*t - 5;
velocity = [diff(x, t), diff(y, t), diff(z, t)];
acceleration = diff(velocity, t);
fprintf('Problem 1:');

Problem 1:

pretty(velocity)

( 2 )
-3 t , 2 t, 2

pretty(acceleration)

(-6 t, 2, 0)

time = 1;
direction = [2, 1, 2];
velocity_t = subs(velocity, t, time);
acceleration_t = subs(acceleration, t, time);
vel_component = dot(velocity_t, direction) / norm(direction);
acc_component = dot(acceleration_t, direction) / norm(direction);
fprintf('Velocity component: %f', vel_component);

Velocity component: 0.000000

fprintf('Acceleration component: %f', acc_component);

Acceleration component: -3.333333

syms x y z
f = x^2 * y^3 - 4 * y;
grad_f = gradient(f, [x, y, z]);
fprintf('Problem 2:');

Problem 2:

5
pretty(grad_f)

/ 3 \
| 2 x y |
| |
| 2 2 |
| 3 x y - 4 |
| |
\ 0 /

F = [x * y, x^2, 0];
div_F = divergence(F, [x, y, z]);
fprintf('Problem 3:');

Problem 3:

pretty(div_F)

F = [y * z, 3 * x * z, z];
curl_F = curl(F, [x, y, z]);
fprintf('Problem 4:');

Problem 4:

pretty(curl_F)

/ -3 x \
| |
| y |
| |
\ 2 z /

phi = 4 * x^2 * z - 3 * x^2 * y^2 * z;


point = [2, -1, 2];
direction = [2, -3, 6];
grad_phi = gradient(phi, [x, y, z]);
directional_derivative = dot(subs(grad_phi, [x, y, z], point), direction /
norm(direction));
fprintf('Problem 5:Directional derivative: %f', directional_derivative);

Problem 5:Directional derivative: -14.857143

6
f = 7 * x + 8 * y^2 + 8 * z^3;
point = [3, 4, 5];
direction = [6, -4, 5];
grad_f = gradient(f, [x, y, z]);
directional_derivative = dot(subs(grad_f, [x, y, z], point), direction /
norm(direction));
fprintf('Problem 6:Directional derivative: %f', directional_derivative);

Problem 6:Directional derivative: 317.494166

You might also like