1.p1 = input('Enter coordinates for P1 as [x y]: ');
p2 = input('Enter coordinates for P2 as [x y]: ');
p3 = input('Enter coordinates for P3 as [x y]: ');
% Ask user for rotation angle
theta = input('Enter rotation angle in degrees: ');
rp1 = rotate(p1, theta);
rp2 = rotate(p2, theta);
rp3 = rotate(p3, theta);
% Prepare coordinates for plotting
x_orig = [p1(1), p2(1), p3(1), p1(1)];
y_orig = [p1(2), p2(2), p3(2), p1(2)];
x_rot = [rp1(1), rp2(1), rp3(1), rp1(1)];
y_rot = [rp1(2), rp2(2), rp3(2), rp1(2)];
% Plotting
figure;
plot(x_orig, y_orig, 'b-o', 'DisplayName', 'Original
Triangle'); hold on;
plot(x_rot, y_rot, 'r--o', 'DisplayName', ['Rotated
Triangle (', num2str(theta), '°)']);
axis equal;
grid on;
legend;
title(['Triangle Rotation by ', num2str(theta), '
Degrees']);
xlabel('X');
ylabel('Y');
% Printing the coordinates
fprintf('Rotation %.2f degrees\n', theta);
fprintf('Coordinates of point 1: original [%.2f, %.2f],
after [%.2f, %.2f]\n', p1(1), p1(2), rp1(1), rp1(2));
fprintf('Coordinates of point 2: original [%.2f, %.2f],
after [%.2f, %.2f]\n', p2(1), p2(2), rp2(1), rp2(2));
fprintf('Coordinates of point 3: original [%.2f, %.2f],
after [%.2f, %.2f]\n', p3(1), p3(2), rp3(1), rp3(2));
COMMAND WINDOW:
trianglem
Enter coordinates for P1 as [x y]: [1.11, 1.56]
Enter coordinates for P2 as [x y]: [3.73, 7.05]
Enter coordinates for P3 as [x y]: [2.01, 0.35]
Enter rotation angle in degrees: 30
Rotation 30.0000 degrees
Coordinates of point 1: original [1.11, 1.56], after
[0.1813, 1.9060]
Coordinates of point 2: original [3.7300, 7.05], after [0.2947, 7.9705]
Coordinates of point 3: original [2.01, 0.35], after
[1.5657, 1.3081]
2.%inputs
r = input('Enter the bottom and top radii as [R1 R2] in
cm: ');
h = input('Enter the height of the cup in cm: ');
op = input('Enter option (1 for volume, 2 for surface
area): ');
% Extract radii
R1 = r(1);
R2 = r(2);
% Perform calculation based on option
if op == 1
% Volume calculation
volume = (1/3) * pi * h * (R1^2 + R1*R2 + R2^2);
% Print result
fprintf('Bottom radius = %.2f cm, top radius = %.2f
cm and height = %.2f cm\n', R1, R2, h);
fprintf('Volume is %.2f cm^3\n', volume);
elseif op == 2
% Surface area calculation
S = pi * (R1 + R2) * sqrt((R1 - R2)^2 + h^2);
% Print result
fprintf('Bottom radius = %.2f cm, top radius = %.2f
cm and height = %.2f cm\n', R1, R2, h);
fprintf('Surface area is %.2f cm^2\n', S);
else
fprintf('Program ended. No calculation
performed.\n');
end
COMMAND WINDOW:
cup
Enter the bottom and top radii as [R1 R2] in cm: [3.0,
3.8]
Enter the height of the cup in cm: 9.5
Enter option (1 for volume, 2 for surface area): 1
Bottom radius = 3.00 cm, top radius = 3.80 cm and
height = 9.50 cm
Volume is 346.60 cm^3
Enter the bottom and top radii as [R1 R2] in cm: [3.0,
3.8]
Enter the height of the cup in cm: 9.5
Enter option (1 for volume, 2 for surface area): 2
Bottom radius = 3.00 cm, top radius = 3.80 cm and
height = 9.50 cm
Surface area is 203.67 cm^2
Enter the bottom and top radii as [R1 R2] in cm: [3.0,
3.8]
Enter the height of the cup in cm: 9.5
Enter option (1 for volume, 2 for surface area): 5
Program ended. No calculation performed.
3.function y = mac(x, a, n)
% x - the value where function is evaluated
% a - the shifting point
% n - the exponent
if x < a
y = 0;
else
y = (x - a)^n;
end
end
COMMAND WINDOW
result1 = mac(3, 5, 2)
result1 =
0
result2 = mac(7.2, 5, 2)
result2 =
4.8400