% Prompt user for input vector AM
AM = input('Please enter a vector (e.g., [1, 2, 3, 4]): ');
% Check if the number of elements in AM is even
if mod(length(AM), 2) ~= 0
fprintf('Error: The vector must contain an even number of elements.\n'); else
% Initialize variables for product of even elements and sum of odd elements
product_even = 1; % Start at 1 for multiplication
sum_odd = 0; % Start at 0 for addition
% Iterate through each element in AM
for i = 1:length(AM)
if mod(AM(i), 2) == 0 % Check if the element is even
product_even = product_even * AM(i);
else % The element is odd
sum_odd = sum_odd + AM(i);
end
end
% Calculate PDS
if sum_odd ~= 0 % Prevent division by zero
PDS = product_even / sum_odd;
fprintf('The result PDS is: %.4f\n', PDS
); % Display the result
else
fprintf('Error: Sum of odd elements is zero, cannot compute PDS.\n'); end
end
JSBQcm9tcHQgdXNlciBmb3IgaW5wdXQgdmVjdG9yIEFNCkFNID0gaW5wdXQoJ1BsZWFzZSBlbnRlciBhIHZlY3RvciAoZS5nLiwgWzEsIDIsIDMsIDRdKTogJyk7CgolIENoZWNrIGlmIHRoZSBudW1iZXIgb2YgZWxlbWVudHMgaW4gQU0gaXMgZXZlbgppZiBtb2QobGVuZ3RoKEFNKSwgMikgfj0gMAogICAgZnByaW50ZignRXJyb3I6IFRoZSB2ZWN0b3IgbXVzdCBjb250YWluIGFuIGV2ZW4gbnVtYmVyIG9mIGVsZW1lbnRzLlxuJyk7CmVsc2UKICAgICUgSW5pdGlhbGl6ZSB2YXJpYWJsZXMgZm9yIHByb2R1Y3Qgb2YgZXZlbiBlbGVtZW50cyBhbmQgc3VtIG9mIG9kZCBlbGVtZW50cwogICAgcHJvZHVjdF9ldmVuID0gMTsgJSBTdGFydCBhdCAxIGZvciBtdWx0aXBsaWNhdGlvbgogICAgc3VtX29kZCA9IDA7ICAgICAgJSBTdGFydCBhdCAwIGZvciBhZGRpdGlvbgoKICAgICUgSXRlcmF0ZSB0aHJvdWdoIGVhY2ggZWxlbWVudCBpbiBBTQogICAgZm9yIGkgPSAxOmxlbmd0aChBTSkKICAgICAgICBpZiBtb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