Problem 1; part 1: Quadratic equation (Programming code) Please don\'t write it
ID: 3784448 • Letter: P
Question
Problem 1; part 1:
Quadratic equation (Programming code)
Please don't write it on the paper, write it by computer so I can run it through MATLAB
Write an MATLAB function (M-file) to solve a second-order polynomial:
Ax2 + Bx + C = 0
Request input from the user (three numbers: A, B, and C).
Check for real/imaginary roots
Solve mathematically and store the solutions in variables x1 and x2
Return the solutions to the user (x1, x2)
Remember: annotation and comments are very important in the understanding of your code by another (a grader or faculty member) and you will be graded by the functionality of your code AND the quality of your code, including annotation.
Please don't forget to add comment, so any one read the program should understand your thought.
Explanation / Answer
clear all; format short; a=input(); //taking coefficients as input b=input(); c=input(); rdelta=sqrt(b^2-4*a*c); // calculating discriminant if rdelta < 0 // checking for imaginary roots fprintf('It has imaginary roots') end x1=(-b+rdelta)/(2*a); // calculating roots of the equation x2=(-b-rdelta)/(2*a); fprintf(' Roots of the polynomial %5.3f x^2 + %5.3f x+%5.3f ',a,b,c) fprintf ('x1= %e ',x1) fprintf ('x2= %e ',x2)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.