Question
Write two functions that return the two solutions to the quadratic equation (ax^2) + bx + c = 0. You can write something like function
Write two functions that return the two solutions to the
quadratic equation (ax^2) + bx + c = 0. You can write something like
function [p,q] = quadratic Formula (a,b, c)
For the first function, assign
p = [-b+ sqrt((b^2) - 4ac)]/2a , q = [-b-sqrt((b^2) -4ac)]/2a
Make sure the code works for some trial values of a, b, and c. At least expect
the solutions of a quadratic equation (x^2) - 3x + 2 = 0 are p = 2 and q = 1.
Then try your code for a = 1 b = (-10^12), c = 1. Note that q = 0, which is obviously not a correct root. This is an example of round-off error.
For the second function, assign
p = [-b + sqrt((b^2) -4ac]/2a , q = 2c/ -b+sqrt((b^2)-4ac) , (b < 0) , and
p = 2c/( -b-sqrt((b^2)-4ac)) , q = (-b - sqrt((b^2) -4ac)/2a , (b >= 0)
Again, make sure the code works for some trial values of a, b, and c. Now
try this code for a = 1, b = -10^12 , c = 1 to obtain more reasonable results.
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 StartedRecommended Textbook for
Microeconomics An Intuitive Approach with Calculus
Authors: Thomas Nechyba
1st edition
538453257, 978-0538453257
Students also viewed these Accounting questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App