Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a script for the general solution to the quadratic equation ax^2 + bx + c

ID: 1716037 • Letter: W

Question

Write a script for the general solution to the quadratic equation ax^2 + bx + c = 0. Use the structure plan in Figure 3.3. Your script should be able to handle all possible values of the data a, b, and c. Try it out on the following values: 1, 1, 1 (complex roots) 2, 4, 2 (equal roots of -1.0) 2, 2, -12 (roots of 2.0 and -3.0) The structure plan in Figure 3.3 is for programming languages that cannot handle complex numbers MATLAB can. Adjust your script so that it can also find complex roots. Test it on case (a); the roots are -0.5 plusminus 0.866i.

Explanation / Answer

MATLAB Script :

clc;
clear all;
close all;

disp(' Finding the general Solution of ax^2+bx+c=0');
prompt = 'Enter value of ''a'': ';
a= input(prompt);

prompt = 'Enter value of ''b'': ';
b= input(prompt);

prompt = 'Enter value of ''c'': ';
c= input(prompt);

root1=(-b+sqrt(b^2-4*a*c))/(2*a)
root2=(-b-sqrt(b^2-4*a*c))/(2*a)

OUTPUT:

(a)

Finding the general Solution of ax^2+bx+c=0
Enter value of 'a': 1
Enter value of 'b': 1
Enter value of 'c': 1
root1 =
-0.5000 + 0.8660i
root2 =
-0.5000 - 0.8660i
>>

(b)

Finding the general Solution of ax^2+bx+c=0
Enter value of 'a': 2
Enter value of 'b': 4
Enter value of 'c': 2
root1 =
-1
root2 =
-1
>>

(c)

Finding the general Solution of ax^2+bx+c=0
Enter value of 'a': 2
Enter value of 'b': 2
Enter value of 'c': -12
root1 =
2
root2 =
-3
>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote