def update_residual_model(residual_model, coefficients_to_add, delta, delta_old):
    """Update linear and square terms of the residual model.

    Args:
        residual_model (dict): Dictionary containing the parameters of the
            residual model, i.e. "intercepts", "linear_terms", and "square terms".
        coefficients_to_add (dict): Coefficients used for updating the
            parameters of the residual model.
        delta (float): Trust region radius of the current iteration.
        delta_old (float): Trust region radius of the previous iteration.

    Returns:
        residual_model_updated (dict): Dictionary containing the parameters of
            the residual model with update "linear_terms" and "square_terms".
    """
    residual_model_updated = residual_model.copy()

    residual_model_updated["linear_terms"] = (
        coefficients_to_add["linear_terms"]
        + (delta / delta_old) * residual_model["linear_terms"]
    )

    residual_model_updated["square_terms"] = (
        coefficients_to_add["square_terms"]
        + (delta / delta_old) ** 2 * residual_model["square_terms"]
    )

    return residual_model_updated