Answered step by step
Verified Expert Solution
Question
1 Approved Answer
10:23 Photo ILTE Done Homework assignment 2 1. (10 pts) Create an M file and use for loop and if...else to solve the following
10:23 Photo ILTE Done Homework assignment 2 1. (10 pts) Create an M file and use for loop and if...else to solve the following problem: x= [3,5, 0, -2, -1, 0, -4, 8, 10] For each element in vector x, there is a corresponding element for an output vector y such that: If the element in x is larger than 2, the corresponding y element will have value of 1; If the element in x is smaller than -1, the corresponding y element will have value of -1; If the element in x is between -1 and 2 (including -1 and 2), the corresponding y element will be 0. Check the value of vector y in the command window after run your M file. 2. (15 pts) For a cylindrical tank with a conical base, if the liquid level is low, in the conical part, the volume is simply the conical volume of the liquid (Vcone rh). If the liquid level is midrange in the cylindrical part, the total volume of liquid includes the filled conical part and the partially filled cylindrical part. (a) Write a user-defined function to compute the volume of the tank as a function of given values of R and h. Design the function so that it returns the volume for all cases if the depth h 3R, and return an error message "Overtop" ifh 3R. (b) Write a script to test the function with the following data: R h 09 1-5 1.25 3.8 1.3 4.0 (c) Plot a curve of volume versus depth utilizing the user-defined function for R=1 + 10:23 LTE Photo Content Done 2R R 3. (10 pts) An old-time method for approximating the square root of any positive number a can be formulated as x+a/x 2 Here x is a random initial guess. (a) Write a user-defined function based on if..elseif and while...break loop structure to implement this algorithm. At each step estimate the relative error in the approximation as xnew Xnew Xold Repeat the loop until a is less than or equal to a specified value. If the input a is negative, return an error message. (b) Write a script to test the function by evaluating a = 0,2,10,4 for 8 = 10-1 Bonus: (5 pts) Develop a vectorized version of the following code: tstart=0; tend-20; ni-8; t(1)=tstart; y(1) 12+6*cos(2*pi*t(1)/(tend-tstart)); for i=2:ni+1 MacBook Air +
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started