write a program which takes Input from user an Algebraic function,plot graph, see its roots and values, checks if its real or imaginary

1 view (last 30 days)
I need help regarding writing a program This is the first time I am using MATLAB, I am still learning it please please please help me
write a program that takes input from user (input algebraic function) and plot graph to see its roots and where the values lie and program should also check if the roots are real or imaginary by quadratic equation if roots are imaginary the output should say "roots are imaginary"
  2 Comments
Asim Ali
Asim Ali on 19 Oct 2012
Edited: Walter Roberson on 19 Oct 2012
function [] = Quadratic ()
clc
display('Provide the value of A,B and C for Finding the Roots of Equation ')
a = input('Please enter the value of A: ' );
b = input('Please enter the value of B: ');
c = input('Please enter the value of C: ');
disp('The equation has One real roots')
D = b^2 - 4*a*c
if D> 0
x1 =(-b+ sqrt(b^2-4 *a*c))/(2*a);
x2 = (-b- sqrt (b^2-4 *a*c))/(2*a);
display('The equation has two real roots')
sprintf(' Roots are %d , %d and Descriminent is %d ', x1,x2,D)
elseif D == 0
x1 = -b/2*a;
x2 = x1;
disp('The equation has One real roots')
sprintf(' Roots are %d , %d and Descriminent is %d ', x1,x2,D)
elseif D < 0
x1 =(-b+ sqrt(b^2-4 *a*c))/(2*a);
x2 = (-b- sqrt (b^2-4 *a*c))/(2*a);
disp('The equation has no real roots')
sprintf(' Roots are %d , %d and Descriminent is %d ', x1,x2,D)
end
end
Standard form of Quadratic Equation is:
Ax^2+ BX+C= 0
Where A,B, and C can have any value except that “A” can’t be 0. Just call the Function Quadratic() in Command window, just input the value of A, B and C as Real

Sign in to comment.

Answers (0)

Categories

Find more on Help and Support in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!