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

Matlab

MATLAB ASSIGNMENTS

Uploaded by

netafo3832
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)
35 views

Matlab

MATLAB ASSIGNMENTS

Uploaded by

netafo3832
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/ 4

Assignments

1. The position of a moving particle as a function of time is given by: x = (4-0.1t)sin(0.8t), y=(4-0.1t)cos(0.8t), z=0.4t^(3/2). Plot
the position of the particle for 0≤t≤30
Ans- t = 0:0.1:30;
x = (4 - 0.1*t) .* sin(0.8*t);
y = (4 - 0.1*t) .* cos(0.8*t);
z = 0.4 * t.^(3/2);
figure;
plot3(x, y, z, 'LineWidth', 2);
title('Position of the Particle over Time');
2. An elliptical staircase that decreases in size with height can be modelled by the parametric equations. Find the transpose of null
matrix using MATLAB. X=rcos(t), y=rsin(t), z=ht/2pin where r=ab/rootover[bcos(t)^2+[asin(t)]^2. a and b are the semimajor and
semi-minor axes of the ellipse, h is the staircase height, and n is the number of revolutions that the staircase makes. Make a 3- D
plot of the staircase with a=20m, b=10m, h=18m, and n=5. 0≤t≤2πn.
Ans- a = 20;
b = 10;
h = 18;
n = 5;
t = linspace(0, 2*pi*n, 1000);
r = (a*b) ./ sqrt(b^2 * cos(t).^2 + a^2 * sin(t).^2);
X = r .* cos(t);
Y = r .* sin(t);
Z = (h * t) / (2 * pi * n);
figure;
plot3(X, Y, Z, 'LineWidth', 2);
title('3D Plot of the Elliptical Staircase');
3. Make a 3-D surface plot of function z=x^2/3+2sin(3y) in the domain -3<=x<=3 and -3<=y<=3.
Ans- x = linspace(-3, 3, 100);
y = linspace(-3, 3, 100);
[X, Y] = meshgrid(x, y);
Z = (X.^2) / 3 + 2 * sin(3 * Y);
figure;
surf(X, Y, Z);
title('3-D Surface Plot of z = x^2/3 + 2*sin(3y)');
4. Make a 3-D surface plot of function z=0.5|x|+|y|0.5 in the domain -2<=x<=2 and -2<=y<=2.
Ans- x = linspace(-2, 2, 100);
y = linspace(-2, 2, 100);
[X, Y] = meshgrid(x, y);
Z = 0.5 * abs(X) + abs(Y).^0.5;
figure;
surf(X, Y, Z);
title('3-D Surface Plot of z = 0.5|x| + |y|^{0.5}');
5. Make a 3-D mesh plot of the function z = (sin R)/R where R = sqrt(x ^ 2 + y ^ 2) in the domain - 10 <= x <= 10 and -
10 <= y <= 10
Ans- x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
R = sqrt(X.^2 + Y.^2);
Z = sin(R) ./ R;
Z(R == 0) = 1;
figure;
mesh(X, Y, Z);
title('3-D Mesh Plot of z = sin(R)/R where R = sqrt(x^2 + y^2)');
6. Make a 3-D surface plot of the function z = cos(xy) * cos(sqrt(x ^ 2 + y ^ 2)) in the domain - pi <= x <= pi and - pi <= y <= pi
Ans- x = linspace(-pi, pi, 100);
y = linspace(-pi, pi, 100);
[X, Y] = meshgrid(x, y);
R = sqrt(X.^2 + Y.^2);
Z = cos(X .* Y) .* cos(R);
figure;
surf(X, Y, Z);
title('3-D Surface Plot of z = cos(xy) * cos(sqrt(x^2 + y^2))');
7. The geometry of a ship hull (Wigley hull) can be modeled by the equation y= +- B/2 [1 - ((2x)/L) ^ 2][1 - ((2z)/T) ^ 2] where
x_{x}*y_{z} and are the length, width, and height, respectively. Use MATLAB to make a 3-D figure of the hull as shown. Use B
= 1.2, L=4, T=0.5, - 2 <= x <= 2 -0.5 <= z <= 0.
Ans- x = linspace(-2, 2, 100);
z = linspace(-0.5, 0, 100);
[X, Z] = meshgrid(x, z);
B = 1.2;
L = 4;
T = 0.5;
Y_positive = (B/2) * (1 - ((2*X)/L).^2) .* (1 - ((2*Z)/T).^2);
Y_negative = -Y_positive;
figure;
surf(X, Z, Y_positive, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
hold on;
surf(X, Z, Y_negative, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
title('3-D Figure of the Wigley Hull');
8. An anti-symmetric cross-ply composite laminate has two layers in which the fibers are aligned perpendicular to one another. A
laminate of this type will deform into a sad- dle shape due to residual thermal stresses as described by the equation w = k(x^2-y^2)
where x and y are the in-plane coordinates. w is the out-of-plane deflection, and & is the curvature (a complicated function of
material properties and geometry). Make a surface plot showing the deflection of a six-inch square plate (-3≤x≤3 in., -3≤ y ≤ 3
in.), assuming k = 0.01 in^-1.
Ans- x = linspace(-3, 3, 100);
y = linspace(-3, 3, 100);
[X, Y] = meshgrid(x, y);
k = 0.01; % in^-1
W = k * (X.^2 - Y.^2);
figure;
surf(X, Y, W);
title('Surface Plot of Deflection w = k(x^2 - y^2)');

CLASSWORK
1. Consider the following functions x(t) = e ^ (-0.2t) * cos 2t, y(t) = e ^ (-0.2t) * sin 2t. Do it for 2d and also 3d.
Ans- 2D Plot-
t = linspace(0, 10, 1000);
x = exp(-0.2 * t) .* cos(2 * t);
y = exp(-0.2 * t) .* sin(2 * t);
figure;
plot(x, y);
title('2D Plot of x(t) and y(t)');
3D Plot-
t = linspace(0, 10, 1000);
x = exp(-0.2 * t) .* cos(2 * t);
y = exp(-0.2 * t) .* sin(2 * t);
z = t;
figure;
plot3(x, y, z);
title('3D Plot of x(t), y(t), and t');
2. The MATLAB function meshgrid makes it easy to create the x and y arrays required for these plots. The form of this function is
[x, y]=meshgrid(xstart:xinc:xend, ystart:yine:yend); Create a mesh plot of the function z(x, y) = e ^ (-0.5[x ^ 2 + 0.5 * (x - y) ^ 2]).
We call function mesh, surf, or contour to create the plot.
Ans- x = -5:0.1:5;
y = -5:0.1:5;
[X, Y] = meshgrid(x, y);
Z = exp(-0.5 * (X.^2 + 0.5 * (X - Y).^2));
figure;
mesh(X, Y, Z);
title('Mesh Plot of z(x, y) = exp(-0.5[x^2 + 0.5*(x - y)^2])');
3. z = (x * y ^ 2)/(x ^ 2 + y ^ 2) over the domain - 1 <= x <= 3 and 1 <= y <= 4 . Make mesh and surf.
Ans- Mesh Plot-
x = linspace(-1, 3, 100);
y = linspace(1, 4, 100);
[X, Y] = meshgrid(x, y);
Z = (X .* Y.^2) ./ (X.^2 + Y.^2);
figure;
mesh(X, Y, Z);
title('Mesh Plot of z = (x * y^2) / (x^2 + y^2)');
Surf Plot-
figure;
surf(X, Y, Z);
title('Surface Plot of z = (x * y^2) / (x^2 + y^2)');
4. z = 1.8 ^ (-1.5sqrt(x ^ 2 + y ^ 2)) * sin(x) * cos(0.5y). Over the domain - 3 <= x <= 3 and - 3 <= y <=3. Make mesh, surf, mesh
and contour, surf and contour
Ans- Mesh Plot-
x = linspace(-3, 3, 100);
[X, Y] = meshgrid(x, y);
Z = 1.8 .^ (-1.5 * sqrt(X.^2 + Y.^2)) .* sin(X) .* cos(0.5 * Y);
figure;
mesh(X, Y, Z);
title('Mesh Plot of z = 1.8^{-1.5sqrt(x^2 + y^2)} * sin(x) * cos(0.5y)');
Surf Plot-
figure;
surf(X, Y, Z);
title('Surface Plot of z = 1.8^{-1.5sqrt(x^2 + y^2)} * sin(x) * cos(0.5y)');
Mesh and Contour Plot-
x = linspace(-3, 3, 100);
[X, Y] = meshgrid(x, y);
Z = 1.8 .^ (-1.5 * sqrt(X.^2 + Y.^2)) .* sin(X) .* cos(0.5 * Y);
figure;
mesh(X, Y, Z);
hold on;
contour(X, Y, Z);
title('Mesh and Contour Plot of z = 1.8^{-1.5sqrt(x^2 + y^2)} * sin(x) * cos(0.5y)');
Surf and Contour Plot-
x = linspace(-3, 3, 100);
[X, Y] = meshgrid(x, y);
Z = 1.8 .^ (-1.5 * sqrt(X.^2 + Y.^2)) .* sin(X) .* cos(0.5 * Y);
figure;
surf(X, Y, Z);
hold on;
contour(X, Y, Z);
title('Surf and Contour Plot of z = 1.8^{-1.5sqrt(x^2 + y^2)} * sin(x) * cos(0.5y)');

You might also like