Question
MATLAB code only! please show work on matlab
Cut the Pipes: (adapted from hackerrank.com)) The user will enter the length of several pipes as a vector (all positive integ
0 0
Add a comment Improve this question Transcribed image text
Answer #1

===================== matlab code is ================================================

pipes = input('Enter pipe length in []:');

m = 1;
cut=0;
while m~=0
pipes1 = pipes(pipes>0);
if length(pipes1)==0
m=0;
else
min_val = min(pipes1);
pipes1 = pipes1-min_val;
pipes = pipes1;
cut = cut+1;
end
  
end
fprintf('%d cuts are needed!\n',cut);

------------------------------------------------------------------------------------------------------------------------------------------------------

Screenshots of the code and the output:

-------------------------------------------------------------------------------------------------------------------------------------------------------

pipes = input(Enter pipe length in []:); m = 1; cut=0; while m~=0 pipesl = pipes (pipes>0); if length (pipes1)==0 m=0; else

>> bisection Enter pipe length in [] : [1 2] 2 cuts are needed! >> bisection Enter pipe length in [] : [6 5 5 2 2 8] 4 cuts a

======================================================= end======================

Note: bisection in the screenshots is filename i.e bisection.m :choose your own filename

-----------------------------------------------****************************************---------------------------------------------------

PLEASE LIKE THE POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Add a comment
Know the answer?
Add Answer to:
MATLAB code only! please show work on matlab Cut the Pipes: (adapted from hackerrank.com)) The user...
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
  • Please help with the following matlab code and please show all work. Thank you! Viscous losses in a pipe are expressed...

    Please help with the following matlab code and please show all work. Thank you! Viscous losses in a pipe are expressed in terms of a friction factor, f. It is important to know the frictional forces in pipe flow because they result in pressure loss which must be accounted for in the piping system. For turbulent low in pipes, the friction factor is caleulated using the Colebrook e/D 2.51 where e is the roughness height, D is the pipe diameter...

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

  • Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...

    Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a common task. Often this involves using string functions to manipulate a set of input strings. Create a MATLAB script named namephone.m and place these lines of code at the beginning: name  = input('Enter your first and last name: ','s'); phone = input('Enter your area code and phone number: ','s'); Tasks Here are useful string functions:  length, strcat, strtrim, lower, upper, strcmp, findstr, strrep As you work...

  • MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x...

    MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x's, y's, and v's to popup in the command window so I can put in any value and it will find the value for me using the equation I put in. function project_9_sjl() % PROJECT_9_SJL project_9_sjl() is the driver function for the program. % %    Name: Scott Lawrence %   Date: 3/27/2019 %   Class: CMPSC 200 %   Description: Determine the optimal...

  • Orleans Construction Company Case (adapted from Meredith and Mantel) The Orleans Construction Company, a small construction...

    Orleans Construction Company Case (adapted from Meredith and Mantel) The Orleans Construction Company, a small construction company in North Carolina, has been awarded a contract for the construction of a new 25,000 soccer stadium at Greensboro. The City is hoping to use this facility to attract a new soccer franchise. The construction cannot start earlier than March 2, 2020 (because of the availability of bond funds) and must be completed within 1 year (52 weeks). A penalty clause of $13,000...

  • ***** running late, mere 3 hours left for due time, please help ** #needed in c++...

    ***** running late, mere 3 hours left for due time, please help ** #needed in c++ #inputfile MinPath2.txt 0   SF 1   LA 2   DALLAS 3   CONCORD 4   PHOENIX 5   CHICAGO 6   ST LOUIS 7   BOSTON 8   NY 9   LONDON 10   PARIS 11   TOKYO 12   BANGKOK 13   MEXICO CITY 14   MONTREAL -1   0   1   40 0   2   100 0   4   130 0   8   200 0   9   800 0   10   900 1   2   50 1   3   80 1   4   70 1   8  ...

  • Budgeting for an Academic Department at a State University: Can You Believe the Numbers? INTRODUCTION You...

    Budgeting for an Academic Department at a State University: Can You Believe the Numbers? INTRODUCTION You are the senior accounting faculty member in the business school and your dean, Dean Weller, is asking for help. She is very discouraged after a midyear budget meeting with the Vice President of Finance. The college's Department of Social Work has a large budget deficit, and because of this the VP is inclined towards closing the department entirely or closing its bachelor's program. The...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

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