Soft Computing Lab Labs
Soft Computing Lab Labs
Soft Computing Lab Labs
2
Write a Program to Performing Mathematical Operations
>>
% input for numbers
num1 = input('Enter the first number: ');
num2 = input('Enter the second number: ');
% user's choice
choice = input('Enter your choice (1-4): ');
% Selected operation
if choice == 1
result = num1 + num2;
disp(['Result of Addition: ', num2str(result)]);
elseif choice == 2
result = num1 - num2;
disp(['Result of Subtraction: ', num2str(result)]);
elseif choice == 3
result = num1 * num2;
disp(['Result of Multiplication: ', num2str(result)]);
elseif choice == 4
if num2 ~= 0
result = num1 / num2;
disp(['Result of Division: ', num2str(result)]);
else
disp('Error: Division by zero is not allowed.');
end
else
disp('Invalid choice. Please select a number between 1 and 4.');
end
RESULT ——————————————————————————————
>>
% Define the range of values for x (in radians)
x = linspace(-2*pi, 2*pi, 1000); % 1000 points from -2π to 2π
% Calculate the trigonometric values
y_sin = sin(x); % Sine values
y_cos = cos(x); % Cosine values
y_tan = tan(x); % Tangent values
% Plot the functions
figure;
hold on;
plot(x, y_sin, 'b', 'LineWidth', 1.5); % Plot sine in blue
plot(x, y_cos, 'r', 'LineWidth', 1.5); % Plot cosine in red
plot(x, y_tan, 'g', 'LineWidth', 1.5); % Plot tangent in green
% Set axis limits to manage tangent asymptotes
ylim([-10 10]); % Limit y-axis to avoid extreme values of tangent
% Add labels and title
xlabel('x (radians)');
ylabel('Function value');
title('Trigonometric Functions: Sine, Cosine, and Tangent');
legend('sin(x)', 'cos(x)', 'tan(x)');
% Display the grid
grid on;
hold off;
>>
RESULT---------------------------------------------------------------------------------------
Experiment no. 4
Write a Program in to demonstrates union, intersection, and complement operations:
Experiment no. 5
Write a Program in to demonstrates union, intersection, and complement operations:
% Union of A and B
union_AB = union(A, B);
disp('Union of A and B:');
disp(union_AB);
% Intersection of A and B
intersection_AB = intersect(A, B);
disp('Intersection of A and B:');
disp(intersection_AB);
% Complement of A relative to U
complement_A = setdiff(U, A);
disp('Complement of A relative to U:');
disp(complement_A);
Experiment no. 6
Write a Program to implement De Morgan's Theorem
RESULT ------------------------------------------------------------------------------------------
De Morgan's First Law: (A ∪ B)' = A' ∩ B' Complement of (A ∪ B): 9 10 Intersection of A' and B':
9 10 De Morgan's Second Law: (A ∩ B)' = A' ∪ B' Complement of (A ∩ B): 1 2 3 6 7 8 9 10 Union
of A' and B': 1 2 3 6 7 8 9 10
>>
Experiment no. 1
MATLAB and Its Toolboxes
MATLAB is a high-level programming language used for numerical computation, data analysis,
and visualization. It supports matrix operations, plotting, and simulations. Toolboxes are add-ons
that extend MATLAB’s functionality for specialized tasks.
Conclusion:
Toolboxes add specialized functions to MATLAB, enabling users to perform complex tasks in fields
like signal processing, control systems, machine learning, and more.