Quadratic equation & Minus B

조회 수: 13 (최근 30일)
Fergal Ahern
Fergal Ahern 2019년 5월 15일
답변: Pavi thra 2020년 10월 28일
How do I solve the quadratic equation ax^2+bx+c=0 using the minus b formula, x=-b+- sqrt b^2-4ac/2a on MATLAB
Thank you
  댓글 수: 3
Fergal Ahern
Fergal Ahern 2019년 5월 15일
편집: Fergal Ahern 2019년 5월 15일
Geoff - The program must read in coefficients a,b and c from the keyboard and then calculate the roots of the equation. Do you know how I would verify that real roots are generated?
James Tursa
James Tursa 2019년 5월 15일
To read coefficients from the keyboard, you could use the input function
To see if a number is real, you could use the isreal function

댓글을 달려면 로그인하십시오.

채택된 답변

kirti singh
kirti singh 2019년 5월 16일
The following example code snippet works for accepting the coefficients a,b and c and calculating the roots and finding if they are real or not:
a1 = 'Enter value of a ';
a = input(a1)
b1= 'Enter value of b ';
b = input(b1)
c1= 'Enter value of c ';
c = input(c1)
x1 = (-b + sqrt(b^2 - (4 * a * c))) / (2 * a);
x2 = (-b - sqrt(b^2 - (4 * a * c))) / (2 * a);
t1=isreal(x1);
t2=isreal(x2);
  댓글 수: 1
James Tursa
James Tursa 2019년 5월 16일
Please don't post complete solutions to homework problems.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Pavi thra
Pavi thra 2020년 10월 28일
a1 = 'Enter value of a ';
a = input(a1)
b1= 'Enter value of b ';
b = input(b1)
c1= 'Enter value of c ';
c = input(c1)
x1 = (-b + sqrt(b^2 - (4 * a * c))) / (2 * a);
x2 = (-b - sqrt(b^2 - (4 * a * c))) / (2 * a);
t1=isreal(x1);
t2=isreal(x2);

카테고리

Help CenterFile Exchange에서 Physics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by