subject

Use MATLAB 1. Basic structure: As a first step, write a program that prompts the user for the type of acid, and then uses a switch-case structure to provide the following outputs in response. If the user enters 'strong', then the program outputs 'Very low pH'. If the user enters 'weak', then the program outputs 'Moderately low pH'. For any other response, the program outputs 'Please enter strong or weak.' Paste your code on the answer sheet, along with evidence that your program operates successfully. Note: remember to use the 's' argument with the input function to allow string input by the user. For example:
AcidType = input('Please enter strong or weak for the acid type: ', 's');
2. Strong Acid pH: Next, modify the section of the program for the strong acid to correctly calculate the pH according to Equation (1). First, prompt the user to enter the acid concentration [HA], and then calculate and output the pH. Remember that for a strong acid, [H+] = [HA]. Test your program using [HA] = 0.1, then [HA] = 0.001, and finally [HA] = 0. What about [HA] = –1?
There are actually two different types of problems revealed above. In addition to generating a mathematical error (log of -1), it is physically unreasonable to have a negative concentration, and yet there is nothing to prevent a user from entering such a value.
A different type of problem exists with [HA] = 0. It is possible to have zero acid concentration (i. e., pure water). But in addition to the mathematical problem of trying to calculate log10 (0), the pH of a solution with zero acid should be perfectly neutral, or pH 7.0. In fact, to be physically accurate, anytime that such an acid calculation (for strong or weak acids) produces an [H+] value much less than 10-7 (or 1e-7), the acid has no real effect on the pH of the solution, and it should therefore be reported as a neutral pH = 7.00.
On the answer sheet, write the pseudocode for this portion of the program, incorporating an if-elseif-else structure that will correct the logical problems described above (HA < 0 and HA < 1e-7) and deal with them appropriately. Program and test your algorithm.
3. Weak Acid pH: Now, modify the section of the program for the weak acid. You will need to prompt the user for both [HA] and Ka, and use them to calculate and return the pH of the solution according to equations (3) and (1).
a) You will need to use a similar approach for dealing with user inputs of negative [HA] values; however, the weak acid case requires that you test for <1e-7 values of [H+] after x is calculated in the quadratic formula. Write the pseudocode on the answer sheet.
After programming the algorithm, test it using a typical value of Ka = 1.8 x 10-5 (represented in MATLAB as 1.8e-5) and with [HA] = 0.1, then 0, then -1. Ensure that the output is appropriate for all 3 cases.
b) Next, try testing your function with Ka = -1 and [HA] = 0.1. What happens? Again, in addition to a mathematical/logical error, it makes no physical sense to have negative Ka values. Incorporate an elseif structure to control this user input error along with your previous [HA] error control, and test the program to ensure that it works properly.
4. Menu and Plot: Convert your switch-case structure to a menu structure. In addition to Strong Acid pH and Weak Acid pH buttons, also include a button for Acid pH Plot.
After first verifying that the Strong and Weak options still function properly, program the Plot option to prompt the user for a Ka value (control for negative inputs), and then generate a plot of pH versus [HA] for acid concentrations ranging from 0.01 to 1.0 M. Include the Ka value in the title of the plot. Test your plot option for various values of Ka.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:00
The two main ways in which marketers address the competition with their strategies are by satisfying a need better than a competition and by
Answers: 2
question
Computers and Technology, 23.06.2019 03:30
Ihave a singular monitor that is a tv for my computer. recently, i took apart my computer and put it back together. when i put in the hdmi cord and booted the computer to see if it worked, the computer turned on fine but the screen was blue with "hdmi no signal." i've tried everything that doesn't require buying spare parts, any answer is appreciated!
Answers: 1
question
Computers and Technology, 23.06.2019 08:30
When you interpret the behavior of others according to your experiences and understanding of the world your evaluation is
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
Answers: 2
You know the right answer?
Use MATLAB 1. Basic structure: As a first step, write a program that prompts the user for the type...
Questions
question
Mathematics, 03.07.2020 21:01
Questions on the website: 13722360