Write a function function [x1, x2, flag] - myquad(a,b,c) that computes the roots
ID: 3634344 • Letter: W
Question
Write a function function [x1, x2, flag] - myquad(a,b,c) that computes the roots of the quadratic equation ax2 + br + c = 0. The input arguments a, b and c (which may take any values) are the coefficicnts of the quadratic, and x1 and x2 arc the two roots (if they exist), which may the equal. The output argument flag must return the following values, according to the number and type of roots: You must use the usual formula for solving the roots of a quadratic equation that you learnt in your earlier math classes. You may NOT use any built-in MATLAB command for root-finding of polynomials. Show how your function works by feeding to it a variety of inputs. Your test cases must include inputs that trigger each of the above flags.Explanation / Answer
function(x1,x2,flag)=myquad(a,b,c) a=input('enter the value of a:'); b=input('enter the value of b:'); c=input('enter the value of c:'); if(a==b&&b==c&&c==0) flag=99 end if(a==b&&b==0&&c!=0) flag=0 end if(a=0&&b!=0) flag=1 end if((b^2-4*a*c)>0) flag=2 end end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.