Download - Developing a Solution How to create the computer-based solution for a real-world problem. 1
![Page 1: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/1.jpg)
Developing a Solution
How to create the computer-based solution for a real-world problem.
1
![Page 2: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/2.jpg)
General Idea of This Lesson
Give you methodology
Example problems: “Find the optimum nozzle dimensions for …” “Solve for the optimum path for the robot …” “Find the range of temperatures adequate for …”
In EGR115, most tasks will be:
“Develop a program that ……”
![Page 3: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/3.jpg)
General Terms
As a programmer, keep in mind there are 2 sides to a software The person who writes the software: the programmer The person who uses the software: the user (aka client)
As you (the student) develop software, you will constantly jump back and forth between the two roles.
Your goal as a programmer:
“The programmer should make the user’s life easy.”
3
![Page 4: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/4.jpg)
The 5 step process
Follow these steps in order:
1. State the problem clearly
2. Identify the givens vs. the results wanted This will be referred as the I/O diagram
3. Manually solve the problem
4. Computerize the solution
5. Test, test, test!!!
4
![Page 5: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/5.jpg)
Step 1. State the problem
However easy the problem may seem, it is crucial to fully understand the problem, and clarify details. It can help to put the problem in writing.
For example:
Write a program that “Computes the area of a triangle”
This might bring up questions – like “what do I know about the triangle?”
5
![Page 6: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/6.jpg)
Step 2. Identify the I/O
What do you know about the problem? How do you want to solve it?
6
height
base
![Page 7: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/7.jpg)
Step 2. Identify the I/O
What do you know about the problem? How do you want to solve it?
7
side 1
side 2
angleheight
base
![Page 8: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/8.jpg)
Step 2. Identify the I/O
Remember the Von Neumann architecture? CPU + memory + inputs/outputs devices
The I/O diagram determines which input and output devices the software uses, as well as decide which inputs and output variables are used.
The I/O diagram is a first step to organizing the brainstorming.
8
![Page 9: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/9.jpg)
General frame of an I/O diagram
Arrows indicate and names each given and result Purple boxes indicate which devices are used
9
?
?
?
??
?
?
?
![Page 10: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/10.jpg)
General frame of an I/O diagram
10
INPUT SIDE
?
?
?
??
?
?
?
![Page 11: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/11.jpg)
General frame of an I/O diagram
11
OUTPUT SIDE
?
?
?
??
?
?
?
![Page 12: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/12.jpg)
Applied to the area of triangle
12
COMPUTE THE AREA OF TRIANGLE
![Page 13: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/13.jpg)
Applied to the area of triangle
13
COMPUTE THE AREA OF TRIANGLE
Sides 1 and 2
Angle
Each arrow represents the INPUTS
(=GIVENS)
![Page 14: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/14.jpg)
Applied to the area of triangle
14
AREA OF TRIANGLE
Sides 1 and 2
Angle
External interface – What DEVICE is used to enter the values of the givens
Keyboard
Each arrow represents the INPUTS
(=GIVENS)
![Page 15: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/15.jpg)
Applied to the area of triangle
15
COMPUTE THE AREA OF TRIANGLE
Sides 1 and 2
Angle
Keyboard
Each arrow represents the INPUTS
(=GIVENS)
area
Each arrow represents the OUTPUTS
(=RESULTS)
![Page 16: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/16.jpg)
Applied to the area of triangle
16
COMPUTE THE AREA OF TRIANGLE
Sides 1 and 2
Angle
External interface – What DEVICE is used to see the results
Keyboard
Each arrow represents the INPUTS
(=GIVENS)
Screenarea
Each arrow represents the OUTPUTS
(=RESULTS)
![Page 17: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/17.jpg)
Applied to the area of triangle
Final I/O diagram
17
COMPUTE THE AREA OF TRIANGLE
Sides 1 and 2
Angle
Keyboard Screenarea
![Page 18: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/18.jpg)
Same problem: Option 2
18
COMPUTE THE AREA OF TRIANGLE
Sides 1 and 2
Angle
Printer
Different input/output devices
area
18
Microphone
![Page 19: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/19.jpg)
… or option 3 …
19
COMPUTE THE AREA OF TRIANGLE
base
height
Screenarea
19
Keyboard
Different Inputs
![Page 20: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/20.jpg)
Some Other More Complex Examples (and yet, the I/O is not so complex)
2020
ATM MACHINE
![Page 21: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/21.jpg)
Some Other More Complex Examples (and yet, the I/O is not so complex)
2121
ATM MACHINE
Account numberCard
![Page 22: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/22.jpg)
Some Other More Complex Examples (and yet, the I/O is not so complex)
2222
ATM MACHINEpin
Deposit/with-draw/transfer…
Touch Screen/ pin pad
Account numberCard
![Page 23: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/23.jpg)
Some Other More Complex Examples (and yet, the I/O is not so complex)
2323
ATM MACHINEpin
Deposit/with-draw/transfer…
Touch Screen/ pin pad
Account numberCard
Money Slot
money
![Page 24: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/24.jpg)
Some Other More Complex Examples (and yet, the I/O is not so complex)
2424
ATM MACHINEmoney Money Slotpin
Deposit/with-draw/transfer…
Touch Screen/ pin pad
Account numberCard
Money Slot
money
![Page 25: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/25.jpg)
Some Other More Complex Examples (and yet, the I/O is not so complex)
2525
ATM MACHINEmoney Money Slotpin
Deposit/with-draw/transfer…
Touch Screen/ pin pad
Account numberCard
receiptReceipt Slot
Money Slot
money
![Page 26: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/26.jpg)
Step3. Manually Solve Problem
Solving the area of a triangle is obvious (right?)
Height = 3 in Base = 2 in
Area = ½ * 2 * 3
= 3 in squared
26
![Page 27: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/27.jpg)
Step 4 and Step 5
These steps actually involve owning a computer and starting to type ‘lines of code’.
Realize that none of the steps before did this.
In short: Step 4 – Computerize the solution Step 5 – Test the software created
![Page 28: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/28.jpg)
Remember: “SIMCT”(or: Small iPods Make Copying Tough)
1. S State the problem (clarify it if need be)
2. I Identify the Inputs and Outputs
3. M Manually solve the problem
4. C Computerize the solution1. Layout the algorithm
2. Provide the code that implements the algorithm
5. T test, Test, TEST!!
28
![Page 29: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/29.jpg)
1. S State the problem (clarify it if need be)
2. I Identify the Inputs and Outputs
3. M Manually solve the problem
4. C Computerize the solution1. Layout the algorithm
2. Provide the code that implements the algorithm
5. T Test, Test, TEST!!
Remember: “SIMCT”(or: Small iPods Make Copying Tough)
29
Note: I and M are sometimes reversed. You may need to decide what method you will use to solve the problem before you can determine what inputs are needed and what outputs will be provided. In fact, sometimes the problem being solved gets changed. But we will assume the standard SIMCT model.
![Page 30: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/30.jpg)
Developing a SolutionComplete Example
Development of software which finds the roots of any quadratic equation:
ax2 + bx + c = 0
30
![Page 31: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/31.jpg)
1: State the problem
The client says:
“I want a computer program that will find the roots of any quadratic equation”
31
![Page 32: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/32.jpg)
1 (cont.):
The programmer wonders:
Any quadratic equation?
Inputs:
What if the coefficient “a” is 0?
Outputs:
What if the roots are imaginary?
And the client re-considers..
32
![Page 33: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/33.jpg)
1 (cont.):
Client clarifies his requirements:
“I want a computer program that will find the REAL roots of a quadratic equation for all REAL coefficients a, b, and c such that a≠0.”
This shows a much more thorough consideration of the problem.
33
![Page 34: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/34.jpg)
2: Identify Inputs/Outputs What are the inputs for this problem?
In other words, what information is needed
FROM OUTSIDE THE PROGRAM
for the desired program to solve the problem?
In our programs, these inputs typically come from the user – but they don’t have to. Sensors and other programs can provide information, too.
34
![Page 35: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/35.jpg)
2 (cont.):
Inputs, continued…
The only information needed from outside the program are the values of the coefficients:
a?
b?
c?
35
![Page 36: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/36.jpg)
2 (cont.):
What is expected as output from this program?
The roots (x1, and x2) of course. But…
- what about error messages – when the user puts in bad information?
- what about an “imaginary roots found” message?
36
![Page 37: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/37.jpg)
2 (cont.):
Outputs, continued:
- The roots, if real
- Message if roots are imaginary
- Error if the user inputs bad values
37
![Page 38: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/38.jpg)
2 (cont.):
Final I/O diagram:
38
*** magic ***
Coefficients a,b and c
Roots/ error message screenKeyboard
![Page 39: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/39.jpg)
Step 3: Manually solve the problem
Not always practical to actually solve the problem…
e.g. can you manually launch the shuttle?
But…
a programmer must be able to solve the problem manually, assuming all the time and resources necessary were available. Otherwise, how could a programmer tell the computer how to do it???
39
![Page 40: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/40.jpg)
3 (cont.): For this problem, manually solve the quadratic
equation for various inputs. Pretend you are the program you will be writing. What should YOU do if the user provides:
- good data
- bad data
- data that gives real roots
- data that gives imaginary roots40
![Page 41: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/41.jpg)
3 (cont.):
41
Test case #1: enter a valid case (http://www.algebra1help.com/tutorials/math-worksheets-for-mean-mode-median-6th-grade.html
)
![Page 42: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/42.jpg)
3 (cont.):
42
Test case #2: enter 0 for a expect an error message
Test case #3: enter a=4, b=-2, c=0 expect "imaginary roots" message
http://www.videolife.tk/discriminant/
![Page 43: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/43.jpg)
4: Computerize
4.1 Algorithm Describe the steps taken when the problem was
manually solved.
This is more difficult than it seems. Humans perform actions subconsciously – we’re not even aware we are doing them!
43
![Page 44: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/44.jpg)
4.1 (cont.):
Layout the algorithm in “skeleton” form:
% Collect the inputs from the user% Apply the inputs to the quadratic formula% Display the results
44
![Page 45: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/45.jpg)
4.1 (cont.): Now, “flesh it out”
% Collect the inputs from the user% Print error message if bad inputs% Apply the inputs to the quadratic formula% Compute the discriminant (b2-4ac)% If discriminant < 0
% display ‘Imaginary roots’% Otherwise
% compute real roots% Display the results
45
![Page 46: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/46.jpg)
4.2: code
For each step of the algorithm, write code (in this class, MATLAB code) that will perform the actions you have specified. Avoid proceeding to the next step until you feel certain the step has been accomplished. It is important to test as you go.
(Actual coding steps will be learned this semester)
46
![Page 47: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/47.jpg)
5: test, Test, TEST!!! It is provably impossible to write a computer
program to test another arbitrary computer program for correctness. And it’s usually too time consuming to write a program that specifically tests the program we’re writing – so we resort to manual testing.
For complicated programs, it is not possible to test a program too thoroughly because it is not possible to test all inputs. And it may be worth writing that test program after all…
Choose inputs to maximize confidence that the solution written will work correctly.
47
![Page 48: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/48.jpg)
5 (cont.):
For a quadratic solver, each set of input should be tested, which means:
48
a<0, b<0, c<0a<0, b<0, c=0a<0, b<0, c>0a<0, b=0, c<0a<0, b=0, c=0a<0, b=0, c>0a<0, b>0, c<0a<0, b>0, c=0a<0, b>0, c>0
a=0, b<0, c<0a=0, b<0, c=0a=0, b<0, c>0a=0, b=0, c<0a=0, b=0, c=0a=0, b=0, c>0a=0, b>0, c<0a=0, b>0, c=0a=0, b>0, c>0
a>0, b<0, c<0a>0, b<0, c=0a>0, b<0, c>0a>0, b=0, c<0a>0, b=0, c=0a>0, b=0, c>0a>0, b>0, c<0a>0, b>0, c=0a>0, b>0, c>0
![Page 49: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/49.jpg)
Step5 (cont.)
Of course, with human ingenuity, change the design of the program (i.e. modify the algorithm) to avoid some of these:
% If no error condition (such as a equal 0)% then compute the roots% Otherwise, just print the error message
With this sort of technique, we can avoid having to test nearly 1/3 of the possibilities!
49
![Page 50: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/50.jpg)
Step5 (cont.)
For a quadratic solver, each set of input should be tested, which means:
50
a<0, b<0, c<0a<0, b<0, c=0a<0, b<0, c>0a<0, b=0, c<0a<0, b=0, c=0a<0, b=0, c>0a<0, b>0, c<0a<0, b>0, c=0a<0, b>0, c>0
a=0, b<0, c<0a=0, b<0, c=0a=0, b<0, c>0a=0, b=0, c<0a=0, b=0, c=0a=0, b=0, c>0a=0, b>0, c<0a=0, b>0, c=0a=0, b>0, c>0
a>0, b<0, c<0a>0, b<0, c=0a>0, b<0, c>0a>0, b=0, c<0a>0, b=0, c=0a>0, b=0, c>0a>0, b>0, c<0a>0, b>0, c=0a>0, b>0, c>0
![Page 51: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/51.jpg)
% Collect the inputs from the user
% If no error condition
% Compute the discriminant (b2-4ac)
% If discriminant < 0
% display ‘Imaginary roots’
% Otherwise
% compute real roots
% Display the results
% Otherwise
% Print error message
51
Develop your
algorithm first
![Page 52: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/52.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);
% If no error condition
% Compute the discriminant (b2-4ac)
% If discriminant < 0
% display ‘Imaginary roots’
% Otherwise
% compute real roots
% Display the results
% Otherwise
% Print error message
52
![Page 53: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/53.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error condition
% Compute the discriminant (b2-4ac)
% If discriminant < 0
% display ‘Imaginary roots’
% Otherwise
% compute real roots
% Display the results
% Otherwise
% Print error message
53
![Page 54: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/54.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error conditionif a~=0 %means a not equal to zero, could have done (a<0 || a>0)
% Compute the discriminant (b2-4ac)
% If discriminant < 0
% display ‘Imaginary roots’
% Otherwise
% compute real roots
% Display the results
% Otherwiseelse
% Print error message
end54
![Page 55: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/55.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error conditionif a~=0 %means a not equal to zero, could have done (a<0 || a>0)
% Compute the discriminant (b2-4ac)
% If discriminant < 0
% display ‘Imaginary roots’
% Otherwise
% compute real roots
% Display the results
% Otherwiseelse
% Print error messagedisp(‘error: a invalid’)
end55
![Page 56: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/56.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error conditionif a~=0 %means a not equal to zero, could have done (a<0 || a>0)
% Compute the discriminant (b2-4ac)discriminant = b^2-4*a*c;
% If discriminant < 0
% display ‘Imaginary roots’
% Otherwise
% compute real roots
% Display the results
% Otherwiseelse
% Print error messagedisp(‘error: a invalid’)
end56
![Page 57: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/57.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error conditionif a~=0 %means a not equal to zero, could have done (a<0 || a>0)
% Compute the discriminant (b2-4ac)discriminant = b^2-4*a*c;
% If discriminant < 0if discriminant<0
% display ‘Imaginary roots’
% Otherwiseelse
% compute real roots
% Display the results
end% Otherwiseelse
% Print error messagedisp(‘error: a invalid’)
end57
![Page 58: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/58.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error conditionif a~=0 %means a not equal to zero, could have done (a<0 || a>0)
% Compute the discriminant (b2-4ac)discriminant = b^2-4*a*c;
% If discriminant < 0if discriminant<0
% display ‘Imaginary roots’disp(‘Imaginary Roots’)
% Otherwiseelse
% compute real roots
% Display the results
end% Otherwiseelse
% Print error messagedisp(‘error: a invalid’)
end58
![Page 59: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/59.jpg)
% Collect the inputs from the usera = input(‘Enter coefficient a: ’);b = input(‘Enter coefficient b: ’);c = input(‘Enter coefficient c: ’);
% If no error conditionif a~=0 %means a not equal to zero, could have done (a<0 || a>0)
% Compute the discriminant (b2-4ac)discriminant = b^2-4*a*c;
% If discriminant < 0if discriminant<0
% display ‘Imaginary roots’disp(‘Imaginary Roots’)
% Otherwiseelse
% compute real rootsx1 = (-b + sqrt(discriminant)) / (2*a);x2 = (-b - sqrt(discriminant)) / (2*a);% Display the resultsfprintf(‘x1 = %.2f and x2 = %.2f\n’,x1,x2)
end% Otherwiseelse
% Print error messagedisp(‘error: a invalid’)
end59
![Page 60: Developing a Solution How to create the computer-based solution for a real-world problem. 1](https://reader030.vdocument.in/reader030/viewer/2022032708/56649e7d5503460f94b800d3/html5/thumbnails/60.jpg)
Wrapping Up What are the 5 steps?
1. State the problem Do research if the problem is not clear enough
2. Identify the Inputs/Outputs (Givens/Results) Create an I/O diagram Which devices are used for each side?
3. Manually solve the problem 4. Computerize the solution
4.1 Set up the algorithm 4.2 Code
5. test, Test, TEST!!!
60