Bleh
Program 1: MATLAB Interface Handling for Basic Commands
clc; % Clear command window
clear; % Clear workspace
disp('MATLAB Interface Handling Demo');
% Display MATLAB version
ver;
% Show path to a specific function
which sin;
% Get help on a MATLAB function
help plot;
% Display current folder contents
dir;
% Check working directory
pwd;
Program 2: Create, Overwrite Variables, Handle Errors, and Make Corrections
clc; clear;
% Creating variables
a = 10;
b = [1 2 3 4];
c = a + b;
% Overwriting variable
a = 25;
disp(['Updated value of a: ', num2str(a)]);
% Error Handling
try
d = [1 2 3] + [1; 2; 3]; % Intentional dimension mismatch
catch ME
disp(['Error occurred: ', ME.message]);
% Correction
d = [1 2 3] + [1 2 3];
disp('Corrected operation:');
disp(d);
end
Program 3: Control Appearance of Floating-Point Numbers
clc; clear;
x = pi;
disp('Default format:');
disp(x);
format short;
disp('Short format:');
disp(x);
format long;
disp('Long format:');
disp(x);
format bank;
disp('Bank format:');
disp(x);
format compact; % Less spacing in display
disp('Compact format applied');
format; % Reset to default
Program 4: Manage Workspace
clc; clear;
x = 1:5;
y = rand(1,5);
z = sum(y);
whos;
save('myWorkspace.mat');
clear y;
disp('After clearing y:');
whos;
load('myWorkspace.mat');
disp('After reloading workspace:');
whos;
clear all;
Program 5: Trigonometric, Exponential, and Logarithmic Functions
clc; clear;
x = 0:pi/4:2*pi;
sinx = sin(x);
cosx = cos(x);
tanx = tan(x);
expVals = exp(1:5);
logVals = log([1 exp(1) 10]);
log10Vals = log10([1 10 100]);
disp('Sine values:');
disp(sinx);
disp('Exponential values:');
disp(expVals);
disp('Natural log values:');
disp(logVals);
Program 6: Matrix and Statistical Operations
clc; clear;
A = [1 2 3; 4 5 6; 7 8 9];
B = [9 8 7; 6 5 4; 3 2 1];
C = A + B;
D = A * B;
E = A .* B; % elementwise
detA = det(A);
invA = inv(A + eye(3)); % avoid singular matrix
disp('Matrix addition:');
disp(C);
disp('Matrix multiplication:');
disp(D);
disp(['Determinant of A: ', num2str(detA)]);
data = randn(1,100);
meanVal = mean(data);
medianVal = median(data);
stdVal = std(data);
varVal = var(data);
fprintf('Mean = %.3f, Median = %.3f, Std = %.3f\n', meanVal, medianVal, stdVal);
Program 7: Array Multiplication and Division
clc; clear;
A = [2 4 6; 8 10 12];
B = [1 2 3; 4 5 6];
C = A .* B; % Elementwise multiplication
D = A ./ B; % Elementwise division
disp('Elementwise Multiplication:');
disp(C);
disp('Elementwise Division:');
disp(D);
Program 8: Various Mathematical Functions
clc; clear;
x = -3.7;
disp(['abs(x): ', num2str(abs(x))]);
disp(['ceil(x): ', num2str(ceil(x))]);
disp(['floor(x): ', num2str(floor(x))]);
disp(['round(x): ', num2str(round(x))]);
disp(['sign(x): ', num2str(sign(x))]);
disp(['sqrt(16): ', num2str(sqrt(16))]);
disp(['factorial(5): ', num2str(factorial(5))]);
disp(['gamma(2.5): ', num2str(gamma(2.5))]);
Program 9: Create Effective Plots
clc; clear;
x = 0:0.1:2*pi;
y1 = sin(x);
y2 = cos(x);
plot(x, y1, 'r-', 'LineWidth', 1.5);
hold on;
plot(x, y2, 'b--', 'LineWidth', 1.5);
xlabel('X-axis');
ylabel('Y-axis');
title('Sine and Cosine Functions');
legend('sin(x)', 'cos(x)');
grid on;
hold off;
% Save plot
saveas(gcf, 'sine_cosine_plot.png');
Program 10: Visualize Data Distributions
clc; clear;
data = randn(1000,1);
subplot(2,2,1);
histogram(data,30);
title('Histogram');
subplot(2,2,2);
boxplot(data);
title('Boxplot');
subplot(2,2,3);
qqplot(data);
title('QQ Plot');
subplot(2,2,4);
ksdensity(data);
title('Kernel Density');
Program 11: MATLAB Debugger Functionalities
clc; clear;
dbstop if error;
n = 5;
result = debugFunction(n);
disp(['Result = ', num2str(result)]);
dbclear if error;
function out = debugFunction(n)
a = sqrt(n);
s = 0;
for k = 1:n
s = s + k;
end
out = a + s;
end