Question

Help with MATLAB.

EXERCISE 6 Ask user to enter the coefficients of a quadratic equation, Ax² + Bx + C = 0, i.e. A, B, and C, and calculate the

i did like

input('enter the coefficients of a quadratic equation "Ax2 + Bx + C = 0"')
fx=(-B+sqrt(B^2+4*A*C))/(2*A);

i just dont know how i can ask the user to input three (A,B,C)?

thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You have to take input as a vector . If you want to take all coefficients at once .

Code :

W NA we are taking coefficients as a vector 2 coeff = input(Enter the coefficients of quadratic equation Ax^2 +Bx + C :); 3Output :

>> quaddd Enter the coefficients of quadratic equation Ax^2 +Bx + C :(1 10 -24] Rooti is 2.000000 Root2 is -12.000000Raw_code :

%we are taking coefficients as a vector
coeff = input('Enter the coefficients of quadratic equation Ax^2 +Bx + C :');
%assigning values in coeff to A,B,C
A = coeff(1);
B = coeff(2);
C = coeff(3);
Root1 = (-B + sqrt((B^2)-4*A*C))/2*A; %from given formula
Root2 = (-B - sqrt((B^2)-4*A*C))/2*A;
fprintf('Root1 is %f\n',Root1);
fprintf('Root2 is %f\n',Root2);


%in case if you want to print roots as complex numbers , USE THIS

%fprintf('Roots are %.2f+%.2fj and.2f+%.2fj\n',real(Root1),imag(Root1),real(Root2),imag(Root2))

Add a comment
Know the answer?
Add Answer to:
Help with MATLAB. i did like input('enter the coefficients of a quadratic equation "Ax2 + Bx...
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
  • The two roots of the quadratic equation ax2 + bx + c = 0 can be...

    The two roots of the quadratic equation ax2 + bx + c = 0 can be found using the quadratic formula as -b+ v62 – 4ac . -b-v6² – 4ac 1 X1 = - and x2 = 2a 2a When b2 – 4ac < 0 this yields two complex roots - -b V4ac – 62 -b Vac – 6² x1 = = +. . 2a 2a i. and x2 = . za 2al Using the quadratic formula the roots of...

  • 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...

  • 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...

  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a,...

    Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a, b and c. Which will represent the coefficients in the quadratic equation ax2 + bx + c = 0. Print out the solutions (if any) of the quadratic equation. If no root exists (this happens if a == 0, or b2 <4ac) print the message No real root. Sample input/ user entries shown in red Corresponding output Enter a, b and c which represent...

  • Java Programming Question 4 (10 points): Solutions for a quadratic equation ax(squared)+bx+c= 0. where a does...

    Java Programming Question 4 (10 points): Solutions for a quadratic equation ax(squared)+bx+c= 0. where a does not equal zero are as follows. r1=( −b+√b(squared)−4ac)/2a r2=(−b−√b(squared)−4ac)/2a if b(squared)−4ac <0, equation doesn’t have real roots. If it is 0 there is one root(r1=r2). Write a Java program to read a,b and c from keyboard and find the roots, if they exist. Note: You need to have a method that takes 3 real values as arguments

  • please answer this question with python. Write a program to solve the quadratic equation ax^2 +...

    please answer this question with python. Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...

  • Recall the quadratic equation ax2​ ​+ bx + c = 0. Prove that there does not...

    Recall the quadratic equation ax2​ ​+ bx + c = 0. Prove that there does not exist any integer solution to this equation if a, b, and c are all odd integers. (No integer solution means that there does not exist any integer x that satisfies the equation ax2​ ​+ bx + c = 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