function energy()
    % Clears command window, closes all figures, and clears workspace
    clc;
    close all;
    clear;
    
    % Define the speed of light (c) in m/s
    c = 2.9979e8; 
    
    % Input: Mass vector from user
    m = input('Enter a vector of masses in kg: ');
    
    % Ensure the input is a valid numeric vector
    if ~isnumeric(m) || isempty(m)
        error('Input must be a numeric vector.');
    end
    
    % Compute energy values using E = mc^2
    E = m .* (c^2);
    
    % Display results
    disp('Mass (kg)      Energy (J)');
    disp([m(:), E(:)]);
    
    % Save results to an Excel file
    filename = 'Energy_Data.xlsx';
    data = [m(:), E(:)];
    headers = {'Mass (kg)', 'Energy (J)'};
    
    % Write headers and data to an Excel file
    writematrix(headers, filename, 'Sheet', 1, 'Range', 'A1');
    writematrix(data, filename, 'Sheet', 1, 'Range', 'A2');
    
    % Plot energy vs mass (Standard plot)
    figure(1);
    plot(m, E, 'bo-', 'LineWidth', 2);
    xlabel('Mass (kg)');
    ylabel('Energy (J)');
    title('Energy vs Mass (Standard Plot)');
    grid on;
    
    % Logarithmic plots in a single figure using subplots
    figure(2);
    
    subplot(2,2,1);
    semilogx(m, E, 'r*-');
    xlabel('Mass (kg)');
    ylabel('Energy (J)');
    title('Semilogx: Log Scale on X-axis');
    grid on;
    
    subplot(2,2,2);
    semilogy(m, E, 'g*-');
    xlabel('Mass (kg)');
    ylabel('Energy (J)');
    title('Semilogy: Log Scale on Y-axis');
    grid on;
    
    subplot(2,2,3);
    loglog(m, E, 'm*-');
    xlabel('Mass (kg)');
    ylabel('Energy (J)');
    title('Loglog: Log Scale on Both Axes');
    grid on;
    
    % Adjust subplot layout for better visualization
    subplot(2,2,4);
    text(0.1, 0.5, 'Logarithmic Analysis of Energy vs Mass', 'FontSize', 12, 'FontWeight', 'bold');
    axis off;
    
    % Notify user about file storage
    fprintf('Energy values have been saved to %s\n', filename);
    
    % Sample Output
    fprintf('\nSample Output:\n');
    fprintf('Enter a vector of masses in kg: [1 5 10 50 100]\n');
    fprintf('\nMass (kg)      Energy (J)\n');
    sample_m = [1 5 10 50 100];
    sample_E = sample_m .* (c^2);
    fprintf('%-12.4f %-12.4e\n', [sample_m; sample_E]);
    fprintf('\nEnergy values have been saved to Energy_Data.xlsx\n');
end
