write a function called calcrmse that given 2 input vectors checks to see if the vectors are the same size. outputs the residual, sum of square errors, and root mean squared error between the vectors in matlab

main.m
function [residual, sum_sq_errors, rmse] = calcrmse(vec1, vec2)
    % Check if vectors are of the same size
    if numel(vec1) ~= numel(vec2)
        error('Input vectors must be of the same size');
    end
    
    % Calculate the residual
    residual = vec1 - vec2;
    
    % Calculate the sum of square errors
    sum_sq_errors = sum(residual.^2);
    
    % Calculate the root mean squared error
    rmse = sqrt(mean(residual.^2));
end
442 chars
16 lines

related categories

gistlibby LogSnag