Question
This is a code in MATLAB
THE HALCYON DAYS OF ERROR-CHECKING IN ENGR 2060 As usual, turn in your Matlab function & script for Problem #1. 1) Write a function that will accept an arbitrary number of input arguments (where the input arguments are n x m real- valued, numerical arrays, where 1 n<oo and 1Srn<㏄). This function will return two values: the number of input arguments given by the user, and b. a. the sum of all the elements of all the arrays. e.g. ifa-1 2; 341, b= [3 4 5; 6 7 81, and c=[1 1 1 1:1 1 1 1:1 1 1 1], then you would call the function (named foo below) as follows (with proper response shown): >> [one, two]-foo(a,b,c) one or >>[one, two]=foo (b,c) one: two 45
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% Matlab function that accepts variable length inputs and returns the
% number of inputs in variable one and the sum of all elements of the
% arrays in variable two
function [one,two] = foo(varargin)
one = nargin; % number of inputs to the function
two = 0;
% loop to calculate the sum of elements in input arrays
for i=1:nargin
for j = 1:size(varargin{i},1)
for k=1:size(varargin{i},2)
two = two + varargin{i}(j,k);
end
end
end
end

%end of function

Output:

>> b [3, 4,5:6,7,81; tone, two]foo (a, b, c) one 3 two >>[one, two]foo (b, c) one two 45

Add a comment
Know the answer?
Add Answer to:
This is a code in MATLAB THE HALCYON DAYS OF ERROR-CHECKING IN ENGR 2060 As usual,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. Cut-off frequency of an arbitrary TE or TM mode [Marks 1] Write a function cutoffFreq) in MATLAB that calculates the cut-off frequency of an arbitrary TE or TM mode in a rectangular waveguide,...

    5. Cut-off frequency of an arbitrary TE or TM mode [Marks 1] Write a function cutoffFreq) in MATLAB that calculates the cut-off frequency of an arbitrary TE or TM mode in a rectangular waveguide, with the following input arguments: the intrinsic phase velocity of the waveguide dielectric, c, waveguide transverse dimensions, a and b, and mode indices, m and n. 5. Cut-off frequency of an arbitrary TE or TM mode [Marks 1] Write a function cutoffFreq) in MATLAB that calculates...

  • Write a user-defined MATLAB function that gives a random integer number within a range between two...

    Write a user-defined MATLAB function that gives a random integer number within a range between two numbers. For the function name and arguments, use n = randint(a,b) where the two input arguments a and b are the two numbers and the output argument n is the random number. Use the function in the command window for the following: (a) Generate a random number between 1 and 49. (b) Generate a random number between -35 and -2

  • Write your answer code into one function file on matlab

     Write your answer code into one function file on matlab The spiral of Archimedes. The spiral of Archimedes is a curve described in polar coordinates by the equation r= kθ Where r is the distance of a point from the origin, and d is the angle of that point in radians with respect to the origin. Write a function file to compute the spiral of Archimedes with varying number of inputs (no input, one input, two inputs) for k, 0 and varying number of...

  • Use matlab and write script: Please use n = input('Enter the value of n :') not...

    Use matlab and write script: Please use n = input('Enter the value of n :') not the function command. Consider the following equation 6a + 9b + 20c = n The variables a, b, and c can be thought of as the number (non-negative integers) of 6’s, 9’s, and 20’s in n. Note that for a given n, there might be one, multiple, or no solutions for a, b, and c. For example, n = 15 → a = 1...

  • Matlab code for this problem. 1[35pl Write a user-defined MATLAB function that determines the unit vector...

    Matlab code for this problem. 1[35pl Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the func- tion name and arguments, use n = unitvec (A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corre- sponding point. The output is a vector with the components of the unit vector in the direction from...

  • This is a MATLAB Question. Below is my base code for a Fourier Series of a...

    This is a MATLAB Question. Below is my base code for a Fourier Series of a half triangle wave. So I am being asked to isolate the first 8 components so that only those first 8 components of the half triangle function are calculated by MATLAB fft function, and then afterwards I am asked to do the same thing but with the first 20 components rather than the first 8. How do I isolate the first x number of components...

  • Please provide MATLAB code and plot, about system response. Will thumbs up. Thanks. Question 1: MATLAB contains a built-...

    Please provide MATLAB code and plot, about system response. Will thumbs up. Thanks. Question 1: MATLAB contains a built-in function called conv which performs the convolution of two vectors: >> help conv conv Convolution and polynomial multiplication. C - conv(A, B) convolves vectors A and B. The resulting vector is length MAX ([LENGTH (A)+LENGTH (B)-1, LENGTH(A),LENGTH (B) 1) If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials. Compute the system response...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • MATLAB, Please answer question 1. + ENGR 102 Homework 9 :- 1) An elliptical staircase that...

    MATLAB, Please answer question 1. + ENGR 102 Homework 9 :- 1) An elliptical staircase that decreases in size with height can be modeled by the parametric equations: r cos(t) y-rsint) it m) Where, e-0.04t Ib cos(O)+ [a sin()]- a and b are the semimajor and semiminor axes of the ellipse, h is the staircase height, and n is the number pf revolutions that the staircase makes. Make a 3-D plot of the staircase with a 20 m, b 10...

  • 3) Develop a Matlab function to compute the velocity v of a particular projectile as a...

    3) Develop a Matlab function to compute the velocity v of a particular projectile as a function of time t. In this problem, the velocity profile is described by a piecewise function, and is parameterized by 11 parameters, a, b, c, d, g, h, k, m, n, p, and q, as at - bt, 05158 c-dt, 851516 v(t;a,b,c,d,g,h,k,m,n, p,q) = gt +h(t – k)?, 1651526 me=n(t-p), > 26 else. Your Matlab function must take as input the current time value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT