Borrar filtros
Borrar filtros

Quistion 1: Write a MATLAB program (Script file) Q1_my_average that takes a vector (an array) of values and returns the sum and product of this vector, you need to use two way in solving this question, one of them is using built in function.

2 visualizaciones (últimos 30 días)
ver
  1 comentario
Steven Lord
Steven Lord el 14 de Feb. de 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Iniciar sesión para comentar.

Respuestas (1)

Kautuk Raj
Kautuk Raj el 3 de Jun. de 2023
This is a MATLAB program called my_average that takes a vector of values as input and returns the sum and product of the vector:
function [sum_val, prod_val] = my_average(vec)
% This function takes a vector of values as input and returns the sum and product of the vector.
% Calculate the sum and product of the vector
sum_val = sum(vec);
prod_val = prod(vec);
end
To use this function, we can call it with a vector of values as the argument, like this:
vec = [1, 2, 3, 4];
[sum_val, prod_val] = my_average(vec);
disp(['The sum of the vector is ', num2str(sum_val)]);
disp(['The product of the vector is ', num2str(prod_val)]);
The output can be obtained by simply running the code.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by