Quadratic Formula Script Name: quadratic Script Outputs (2): plus_sol (double) T
ID: 3636779 • Letter: Q
Question
Quadratic Formula Script Name: quadratic Script Outputs (2): plus_sol (double) The plus solution from the quadratic formula minus_sol (double) The minus solution from the quadratic equation Script Description: write a script called -quadratic' that uses the coefficients A, B, and C of a quadratic equation in the form and then applies the quadratic formula to find the two solutions of the equation. Name the first output from the 'plus' solution of the plus-or-minus part of the equation "plus_sol", and name the second output from the 'minus' solution "minus_sol". Inputs: A: 4 B: -10 C: 4 Outputs: plus_sol: 2 minus_sol: 0.5Explanation / Answer
i have written a function for this. to execute the function, u can call the function in the command window as something like: [x,y] = quadratic(a,b,c). x will print the plus_sol and y, the minus_sol. the matlab code is given below. copy it to a new script file and save it as quadratic.m, so that you can understand it better with the colour codes for different parts of the code. function [ plus_sol, minus_sol ] = quadratic( a, b, c ) %quadratic - takes coefficients (a,b,c) as inputs. returns 2 outputs %quadratic function to compute solutions of a quadratic equation ax^2 + bx + c = 0 %to print both outputs, assign the function call to an array. %E.g. [x,y] = quadratic (4,-10,4) gives %x = 2, y = 0.500 plus_sol = (-b + sqrt(b^2-4*a*c))/(2*a); minus_sol = (-b - sqrt(b^2-4*a*c))/(2*a); end