Question

Write a function called calc_crown_area that will receive pairs of lengths of radii as input arguments,...

Write a function called calc_crown_area that will receive pairs of lengths of radii as input arguments, and will return the areas of the crowns. The function should work when: • the inputs are a pair of single values, i.e. one scalar for the inner radius and one scalar for the outer radius. In this case, the function will return one single output for the area. • the inputs are a pair of vectors, i.e. one vector of inner radii (R1) and a corresponding vector of outer radii (R2), of the same length n. In this case the function will return n values for the areas where each is calculated as  * (R2i2 – R1i2) for each i ≤ n. For this case, your code needs to handle the user error when the two vectors provided as inputs do not have the same length. • your code needs to handle the user error when r1 > r2 for both scalar and vector inputs. (pls answer it in Matlab)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function area = calc_crown_area(r1,r2)
if length(r1)~=length(r2)
error('Length of r1 and r2 must be same!!!')
end
if any(r1>r2)
error('r1 must be smaller than r2')
end
area=pi*(r2.^2-r1.^2);

Add a comment
Know the answer?
Add Answer to:
Write a function called calc_crown_area that will receive pairs of lengths of radii as input arguments,...
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
  • The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi...

    The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi and n, and retums two output arguments: a row vector of n2 elements and and n-by-n matrix. The two output arguments must contain the exact same set of random integers that fall between 1 and maxi Do this using the random number genertor, not by reshaping the data Example n,v-randi...

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function...

    Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function samplings at those locations as inputs and returns an approximation of the derivative at the sample points based on forward finite difference method with order of accuracy O(h^3). The function should display nothing to the screen unless an error or warning occurs. The detailed specification is as follows: The approximation of derivative by forward difference method (for O(h^3) is given as: f' (x_1) =...

  • 3. Write a function called sort3 that takes a 3-element vector as its sole arguments. It uses if-statements, possibly nested, to return the three elements of the vector as three scalar output-argumen...

    3. Write a function called sort3 that takes a 3-element vector as its sole arguments. It uses if-statements, possibly nested, to return the three elements of the vector as three scalar output-arguments in nondecreasino-roer , i.e., the first output argument equals the smallest element of the input vector and the last output argument equals the largest element. NOTE: Your function may NOT use any built-in functions, e.g., sort, min, max, median, etc. (5 points) (bonus question). Write a function called...

  • 7. #4. 18 Following is a recursive function which takes as input (argument) a vector $x$...

    7. #4. 18 Following is a recursive function which takes as input (argument) a vector $x$ and returns a scalar. Either by looking carefully at the function, or by running the function with a few simple input vectors and observing the returned values in each case, determine what the function is doing. 29 00- "**{r} 01 - myfun=function(x){ 02 - if(length(x)=-1){return(x) C03 - } else 84 return(x[1]+my funcx[-1])) 205 - ) 206 myfun(c(1:1000)) #here's what happens when it is applied...

  • In this lab, you will write a program that reads a series name/value pairs, and stores...

    In this lab, you will write a program that reads a series name/value pairs, and stores them in a pair of vectors. After the name/value pairs are read, it will then read names (until the input is exhausted) and print out the corresponding value for that name. If the name is not found in the list, "name not found" should be printed. The names should be read as strings and stored as a vector<string>; the values should be read as...

  • LANGUAGE: PYTHON Write a function called: d_polybius(). The function applies the decryption scheme for the polybius...

    LANGUAGE: PYTHON Write a function called: d_polybius(). The function applies the decryption scheme for the polybius cipher scheme above. The start of the function call the get_polybius_square function to get the square as a string. The second scenario when the number of characters is not even, excluding ‘\n’. For instance: “71\n5” is an invalid cipher because there is no way that the last number correspond to a character (we need two numbers). A customized version of Polybius square will be...

  • The program needs to be written in C. Write a function void camelCase(char* word) where word...

    The program needs to be written in C. Write a function void camelCase(char* word) where word consists of more than two words separated by underscore such as “random_word” or "hello_world_my_name_is_sam". camelCase() should remove underscores from the sentence and rewrite in lower camel case” (https:// en.wikipedia.org/wiki/Camel_case). Watch out for the end of the string, which is denoted by ‘\0’. You have to ensure that legal strings are given to the camelCase() function. The program should only run when the input is...

  • Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture...

    Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture i sent is the first page 5. Write and save a function Sphere Area that accepts Radius as input argument, and returns SurfaceArea (4 tt r) as output argument. Paste the function code below. Paste code here 6. Validate your Sphere Area function from the command line, checking the results against hand calculations. Paste the command line code and results below. 7. Design an...

  • matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...

    matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MATLAB's integral function) evaluate the function fx) and the x-axis. The code should output the error between the two calculated areas. area between a Function Inputs Func- the function to be numerically integrated. a-the lower interval value. b-the upper interval value. N-the number of rectangles to be used. Function Outputs: Area Riemann- the numerical approximation for the...

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
ADVERTISEMENT