Question

LAB SECTION: NAME: PERSON C Hw5 Problem 3 (18 points) The following procedure can be used to determine the roots of a cubic equation a3x3 2x2 aux a Set: A and C Calculate: D Q3 R Where Q (3 A2)/9 and (9AB 27c 2A3)/54 If D 0, the equation has complex roots. If D 0, all roots are real and at least two are equal. The roots are given by: 2 WR A/3, and x2 WR A/3 If D 0, all roots are real and are given by: V-Q cos (0/3)- A/3, x 2 V-9 cos e/3 120o) A/3, and x3 2 V-Q cos(6/3 2400) A/3 where cos 0 R/V-Q3. Write a MATLAB program in a script file that determines the real roots of a cubic equation. As input, the program asks the user to enter the values of a3, a2, ai, and ao as a vector. The program then calculates the value of D. If the equation has complex roots the message The equation CCCx +CCC +CCC +CCC has complex roots is displayed. Otherwise the real roots are calculated and displayed as The roots of the equation CCCx 3 +CCCx 2 +CCCX+CCC are XXX, XXX, and XXX. Where CCC refer to the value of the corresponding coefficient, refer to the sign of the coefficient or and XXX refer to the value of the roots. Use fprintf to display the text and data. The data should be displayed in g format Use the program to determine the roots of the following equations (a) 5x3 34.5 x 2 36.9 x 8.8 o (b) 2x 10 x 2 24 x 15 0 (c) x3 9x2 24 x 20 0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab code to find the roots of cubic equation and the code has to be written in script file:-

The code is explained in the form of comments i.e followed by the symbol %

prompt='enter the values of a3,a2,a1,a0 respectively \n'; % to display the message to user
x=input(prompt); % input entered by the user will be stored in x in the form of vector
a3=x(1); % initializing a3
a2=x(2); % initializing a2
a1=x(3); % initializing a1
a0=x(4); % initializing a0
A=a2/a3; % assigning the value of A as given by the formula for A in the given problem
B=a1/a3; % assigning the value of B as given by the formula for B in the given problem
C=a0/a3; % assigning the value of C as given by the formula for C in the given problem
Q=(3*B-A*A)/9; % assigning the value of Q as given by the formula for Q in the given problem
R=(9*A*B-27*C-2*A*A*A)/54; % assigning the value of R as given by the formula for R in the given problem
D=(Q*Q*Q)+(R*R); % assigning the value of D as given by the formula for D in the given problem
formatspec='The equation %4.2fx^3+%4.2fx^2+%4.2fx+%4.2f has complex roots \n';
% formatspecifier to set the format for complex roots
formatspec1='The roots of the equation %4.2fx^3 + %4.2fx^2 + %4.2fx + %4.2f are %4.2f , %4.2f and %4.2f \n';
% formatspecifier to set the format for other than complex roots
if D>0 % for D>0
fprintf(formatspec,x); % print that there are complex roots
end
if D==0 % for D==0
x1=(2*R^(1/3))-(A/3); % caluculate x1
x2= -(R^(1/3))-(A/3); % caluculate x2
x3=x2; % x2 and x3 are equal
fprintf(formatspec1,a3,a2,a1,a0,x1,x2,x3); % print the roots
end
if D<0
t=acosd(R/((-Q)^(3/2))); % caluculate theta
x1=2*((-Q)^(1/2))*(cosd(t/3))-(A/3); % caluculate x1
x2=2*((-Q)^(1/2))*(cosd(t/3+120))-(A/3); % caluculate x2
x3=2*((-Q)^(1/2))*(cosd(t/3+240))-(A/3); % caluculate x3
fprintf(formatspec1,a3,a2,a1,a0,x1,x2,x3); % print the roots
end
  
Output:-

After writing the above code run the program and enter the values for a3,a2,a1 and a0 in the command prompt for the given respective 3 equations to get the following output.

Command Window >> roots enter the values of a3,a2,al, ao respectively [5 -34.5 36.9 8.8 The roots of the equation 5.00x*3-34.

Add a comment
Know the answer?
Add Answer to:
The following procedure can be used to determine the roots of a cubic equation a_3x^3 +...
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
  • 1(a) Find the square roots of the complex number z -3 + j4, expressing your answer in the form a + jb. Hence find the roots for the quadratic equation: x2-x(1- 0 giving your answer in the form p+ q w...

    1(a) Find the square roots of the complex number z -3 + j4, expressing your answer in the form a + jb. Hence find the roots for the quadratic equation: x2-x(1- 0 giving your answer in the form p+ q where p is a real number and q is a complex number. I7 marks] (b) Express: 3 + in the form ω-reje (r> 0, 0 which o is real and positive. θ < 2π). Hence find the smallest value of...

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

  • The purpose of this question is to calculate the three cubic roots of a complex number....

    The purpose of this question is to calculate the three cubic roots of a complex number. A complex number is of the form a + ib where i is v-1. The magnitude r of a complex number is Vab. The complex number a + ib can be written as r(cos θ + i sin θ). Therefore a -r cose and b rsin0 and b/a (r sin0)/(r cos0) - tane e- arctan(b/a). The 3 cubic roots of a complex number are...

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

  • Euler Equation abyg bet r- soume x o ar(rbrco in dicia) equation Case 1. distinet , realroots rr ...

    Please solve this using reduction of order and find a second solution in case 3. Euler Equation abyg bet r- soume x o ar(rbrco in dicia) equation Case 1. distinet , realroots rr Case Q. Complex roots r#Aty; . y; c.xx cos ( μ hlx)) + da Asin (μ In(x) Case3. equal rools r a. VJseducion Use reduchion d order to lind secand 5olution ar(r- br +CO has two ea ual roots Cin 0 Euler Equation abyg bet r- soume...

  • (Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be...

    (Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r1 = (-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 real roots....

  • 2. The roots of the quadratic $a x^2 + b x + c$ are given by...

    2. The roots of the quadratic $a x^2 + b x + c$ are given by $$\frac{-b \pm \sqrt{b^2-4ac}}{2a}$$ If $b^2-4ac <0$, the quadratic has no real roots. Write a function to calculate the real roots of a quadratic. The function should have 3 arguments, *a*, *b* and *c*. If $b^2-4ac <0$, the function should print "quadratic has no real roots", and then return(NULL). Otherwise, the function should return a vector of length 2, those being the real roots (which...

  • Visual Basic You are asked to develop a Visual Basic Net application that can determine roots...

    Visual Basic You are asked to develop a Visual Basic Net application that can determine roots of a requirements of this project are as follows: 1) Design a form to allow users to define a quadratic equation and to find the roots of the equation. The form should have a label that shows this message: Solving a quadratic equation ax2+bx+c=0 The form should have three textboxes in which users enter the values of a, b, and c The form should...

  • 1) Using Matlab, find all real and complex roots of the following polynomial equation: (x-1)(x-2)(x-3)(x-4)(x-5)(x-6)(x-7)=8 2)...

    1) Using Matlab, find all real and complex roots of the following polynomial equation: (x-1)(x-2)(x-3)(x-4)(x-5)(x-6)(x-7)=8 2) Using Matlab, find the root for the following system of equations. Both x and y are positive. a: (x^2)cos(y)=1 b: e^(-4x)+1

  • Find the probability that the three roots of the cubic equation x ^ 3-3ax + 2b...

    Find the probability that the three roots of the cubic equation x ^ 3-3ax + 2b = 0 are real for all values ​​of the coefficients a, b such that | a | <= 3 and | b | <= 6 de que las tres raices de la ecuacion cubica Encontrar la probabilidad c3 -3 ax + 2b 0 sean reales para todos los valores de los oeficientes a, b tales que lal s 3 y lbl s 6.

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