Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2 (Simple Programs Using Selection and Loops) These are from MATLAB - A Practical Introduction to Programming and Problem Solving, by S. Attaway .

image text in transcribed

Part 2 (Simple Programs Using Selection and Loops) These are from MATLAB - A Practical Introduction to Programming and Problem Solving, by S. Attaway . Write a program that solves each problem . Ask the instructor or TA to check your results. PROBLEM #2.1 In chemistry, the pH of an aqueous solution is a measure of its acidity. The pH scale ranges from 0 to 14, inclusive. A solution with a pH of 7 is said to be neutral, a solution with a pH greater than 7 is basic, and a solution with a pH less than 7 is acidic. Write a script that prompts the user (i.e., uses the input function) for the pH of a solution, and then prints whether it is neutral, basic, or acidic. If the user enters an invalid pH, print an error message. Use this name for your script: ph. PROBLEM #2.2 The Pythagorean theorem states that for a right triangle, the relationship between the length of the hypotenuse c and the lengths of the other sides a and b is given by: c2- a2 b2 First, write a function named findh that calculates and returns the length of side b when given a and c as inputs Save your function using this name: findb.m Next, write a script that will prompt the user for the lengths a and c, call the findh function to calculate and return the length of b, and print the result. Note that any values of a or c that are less than or equal to zero would not make sense, so the script should print an error message if the user enters an invalid value. Save your script using this name: py.m PROBLEM #2.3 Write a function sumsteps2 that calculates and returns the sum of 1 to n in steps of 2, where n is an argument passed to the function. For example, if 11 is passed, it will return 1 +3+5+ 7+ 9 + 11, which sums up to 36. Use a for loop to accomplish this task. Calling the function will look like this >> sumsteps2 (11) ans 36 Save your function using this name: sumsteps2.m Submit your work for grading Upload the following items to the appropriate D2L Submission Folder: This document with your answers (saved as a Word docx or PDF file) All of your MATLAB function files and scripts

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

2. Define communication.

Answered: 1 week ago