Question

4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it 4-6 on matlab
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%4

a=input('Enter a: ');
b=input('Enter b: ');
c=input('Enter c: ');

D=b*b-4*a*c;
if D>0
fprintf('The equation has two roots\n%f\t%f\n',(-b+sqrt(D))/(2*a),(-b-sqrt(D))/(2*a))
elseif D==0
fprintf('The equation has one root\n%f\n',(-b)/(2*a))
else
fprintf('The equation has no real roots\n')
end

%%%%%%%%%%%%%%%%%%%%

%5

vec=-10+20*rand([1,20]);

sumPositive=sum(vec(vec>0));

fprintf('Sum of positive elements: %f\n',sumPositive)

%6 is not really a matlab questions

quadEq.m > quadEq Enter a a-inputEnter a: ); b-input (Enter b: ); c inputEnter c: ); Enter b D-b*b-4*a*c; 5 Enter c if

Add a comment
Know the answer?
Add Answer to:
4-6 on matlab 4. Write a program in a script file that determines the real roots...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using matlab and if/else statement please! Write a function that determines the real roots of a...

    Using matlab and if/else statement please! Write a function that determines the real roots of a quadratic equation ax2 + bx + c = 0. To calculate the roots of the equation, the function calculates the discriminant D, given by: D = b2-4ac If D> 0, the code should display "The equation has two roots" and print the values on a new line. If D 0, the code should display "The equation has one root.", and print the value on...

  • reword m the program into a design document diregard the m Write a C++ program that...

    reword m the program into a design document diregard the m Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula -b + b2 - 4ac 2a The value of the discriminant b2 - 4ac determines the nature of roots. If the value of the discriminant is zero, then the equation has a single...

  • In Python. The two roots of a quadratic equation ax^2 + bx + c = 0...

    In Python. The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r2 = (-b - sqrt(b^2 - 4ac) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no...

  • This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation,...

    This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, 0, can be obtained using the following fomula: b 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots. Write a program that prompts the user to enter values for a, b, and cand...

  • The roots of the quadratic equation ax2 + bx + c = 0, a following formula:...

    The roots of the quadratic equation ax2 + bx + c = 0, a following formula: 0 are given by the In this formula, the term i2 - 4ac is called the discriminant. If b4ac 0 then the equation has a single (repeated) root. If -4ac > 0, th equation complex roots. Write a program that prompts the user to input the value of a (the coefficient of ), b (the coefficient of x), and c (the n has two...

  • C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠...

    C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠ 0 are given by the following formula: In this formula, the term b² - 4ac is called the discriminant. If b² - 4ac = 0, then the equation has a single (repeated) root. If b² - 4ac > 0, the equation has two real roots. If b² - 4ac < 0, the equation has two complex roots. Instructions Write a program that prompts the...

  • Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class...

    Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class (name it QuadraticEquation) that represents a quadratic equation of the form of ax2+ bx + x = 0. The class defines the following variables and methods: Private data field a, b, and c that represent three coefficients. A constructor for the arguments for a, b, and c. Three get methods for a, b, and c. Method getDiscriminant()returns the discriminant value, which is disc =...

  • CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation...

    CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation ax +bx+c=0. The roots are given by the formula, x=-b I56²-4ac 2a x = -b+ √b²-4ac 2. x2 = -b-√6²-4ac 2a Instructions: 1. Type, compile, and run the program in an online C++ compiler. 2. Open a word document and copy the following items onto it: a. The source code b. Screenshot of your program's result 3. Save the word document as lastnameFirstname_Lab2.docx (for...

  • Using C++ For this program you are going to create a class that helps to solve...

    Using C++ For this program you are going to create a class that helps to solve the quadratic equation. The equation has the following form: ax2 + bx + c = 0 The roots of the equation are: x1 = -b + sqrt(b2 - 4 * a * c) and x2 = -b - sqrt(b2 - 4 * a * c) The phrase in the parenthesis is called the discriminant. If the value of the discriminant is positive, the equation...

  • Task 3 [35 marks] Write a MIPS program that does the following (in a correct, user-friendly...

    Task 3 [35 marks] Write a MIPS program that does the following (in a correct, user-friendly way):  Greets the user, states the purpose of the program  Sequentially asks the user to provide integer coefficients A,B,C  Calculates discriminant D of quadratic polynomial. (Hint: D = B2 – 4×A×C)  Displays the calculated D value  Checks (in this order) whether discriminant is: o D = 0? Then, displays: “Quadratic polynomial has a sole root.” o D > 0?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT