Using a function that will receive a variable number of values and return using the R equation? - Homework
이전 댓글 표시
There is an equation R = (1/R1 + 1/R2 ... 1/Rn)^-1 I need to write a function that will take in varaibles and (no matter how many varaibles the user inputs), plug them into the equation and give the answer as R.
For example, if the function name is Req, Req(10) will return 10.0. Req(10,10) should return 5.
This is what I have so far. I am not sure how to approach this problem.
function eresistance( x,varargin)
fprintf('There is/are %d input argument.\n', nargin);
for i=1:nargin-1
if ~ischar(varargin{i})
fprintf('Input argument #%d is: %s\n',i, varargin{i});
res = 1/varagin;
inres = (res)^-1;
fprintf('RESISTANCE: %.f\n',inres);
else
disp('PLEASE INPUT NUMBERS ONLY. \n');
end
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!