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

matlab

The document contains multiple assignments related to calculating directional derivatives and solving differential equations using MATLAB. It includes specific functions, points, and directions for which the directional derivatives are computed, along with the outputs of the calculations. Additionally, it presents the results of solving ordinary differential equations (ODEs) and plotting the solutions.

Uploaded by

anitajana127
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

matlab

The document contains multiple assignments related to calculating directional derivatives and solving differential equations using MATLAB. It includes specific functions, points, and directions for which the directional derivatives are computed, along with the outputs of the calculations. Additionally, it presents the results of solving ordinary differential equations (ODEs) and plotting the solutions.

Uploaded by

anitajana127
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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.

dydx = @(x,y) x + y*(cos(x))^2


y0 = 1
xspan = [0 5]
[x ,y] = ode45(dydx ,xspan, y0)
y
figure;
plot(x,y ,'b')
xlabel('x')
ylabel('y')
title('solution')
output
dydx = 1.8260 y= 11.2173
function_handle with 1.9510 13.0842
value: 2.0760 1.0000 15.2409
@(x,y)x+y*(cos(x))^2 2.2010 1.0528 17.6701
y0 = 2.3260 1.1105 20.3197
1 2.4510 1.1733 23.1081
xspan = 2.5760 1.2409 25.9268
0 5 2.7010 1.4288 28.6483
2.8260 1.6411 31.1435
x= 2.9510 1.8713 33.3114
3.0760 2.1112 35.0914
0 3.2010 2.3520 36.4686
0.0502 3.3260 2.5856 37.4908
0.1005 3.4510 2.8064 38.2464
0.1507 3.5760 3.0128 38.8576
0.2010 3.7010 3.2065 39.2151
0.3260 3.8260 3.3941 39.6061
0.4510 3.9510 3.5853 40.0637
0.5760 4.0760 3.7928 40.6210
0.7010 4.2010 4.0319
0.8260 4.3260 4.3195
0.9510 4.4510 4.6750
1.0760 4.5760 5.1198
1.2010 4.7010 5.6783
1.3260 4.7757 6.3780
1.4510 4.8505 7.2493
1.5760 4.9252 8.3247
1.7010 5.0000 9.6372
ASSIGNMENT
dydx = @(x,y) x/y^3 - y/2*x
y1 = 2
xspan = [ 0 10 ]
[x ,y] = ode45(dydx ,xspan, y1)
y
figure;
plot( x , y ,'r')
xlabel('x')
ylabel('y')
title('solution')
output
dydx = 1.7135 y= 1.1893
1.7826 1.1894
function_handle with 1.8517 2.0000 1.1889
value: 1.9208 1.9727 1.1887
1.9899 1.8950 1.1894
@(x,y)x/y^3-y/2*x 2.0590 1.7773 1.1897
2.1281 1.6354 1.1893
2.1972 1.5410 1.1891
y1 = 2.2955 1.4516 1.1893
2.3939 1.3729 1.1895
2 2.4922 1.3090 1.1892
2.5905 1.2869 1.1890
2.6828 1.2677 1.1893
xspan = 2.7751 1.2516 1.1894
2.8674 1.2381 1.1887
0 10 2.9596 1.2270 1.1885
3.0698 1.2181 1.1894
3.1799 1.2110 1.1899
x= 3.2900 1.2055 1.1894
3.4001 1.1994 1.1891
0 3.5301 1.1953 1.1893
0.2500 3.6601 1.1933 1.1895
0.5000 3.7900 1.1921 1.1892
0.7500 3.9200 1.1908 1.1891
1.0000 4.0096 1.1901 1.1893
1.1611 4.0992 1.1898 1.1894
1.3222 4.1888 1.1897 1.1890
1.4833 4.2784 1.1893 1.1888
1.6444 4.3681 1.1891 1.1893
ASSIGNMENT
dydx=@(x,y)(1+(2.71).^(2*x)).^(-1)-y
y0=1
xspan=[0,10]
[x,y]=ode45(dydx,xspan,y0)
figure;
plot(x,y,'b')
xlabel('x')
ylabel('y')
title('solution')

dydx = 2.1519 y= 0.0033


2.4019 0.0027
function_handle with 2.6253 1.0000 0.0022
value: 2.8488 0.9498 0.0018
3.0722 0.8996 0.0015
3.2956 0.8497 0.0012
@(x,y)(1+(2.71).^(2*x)).^(- 3.4993 0.8001 0.0010
1)-y 3.7029 0.6801 0.0008
3.9065 0.5683 0.0007
4.1102 0.4679 0.0006
y0 = 4.3096 0.3805 0.0005
4.5091 0.3063 0.0004
1 4.7085 0.2446 0.0003
4.9080 0.1944 0.0003
5.1058 0.1539 0.0002
xspan = 5.3037 0.1244
5.5015 0.1003
0 10 5.6993 0.0808
5.8965 0.0650
6.0936 0.0532
x= 6.2908 0.0435
6.4879 0.0356
0 6.6848 0.0291
0.1005 6.8816 0.0239
0.2010 7.0785 0.0196
0.3014 7.2753 0.0161
0.4019 7.4720 0.0132
0.6519 7.6687 0.0108
0.9019 7.8654 0.0089
1.1519 8.0621 0.0073
1.4019 8.2588 0.0060
1.6519 8.4554 0.0049
1.9019 8.6521 0.0040
OUTPUT

You might also like