[UP]


Manual Reference Pages  - quadratic (3)

NAME

quadratic(3f) - [M_math] calculate the roots of a quadratic formula even if they are complex

CONTENTS

Synopsis
Description
Options
Returns
Example

SYNOPSIS

subroutine quadratic(a,b,c,z1,z2,discriminant)

   real,intent(in) :: a, b, c
   complex,intent(out) :: z1, z2
   real,intent(out) :: discriminant

DESCRIPTION

Given the equation

      a*x**2+b*x+c=0

Use the quadratic formula to determine the root values and the discriminant of the equation.

OPTIONS

a,b,c coefficients

RETURNS

z1,z2 roots

EXAMPLE

Sample program:

   program demo_quadratic
   use M_math, only : quadratic
   implicit none
   ! Calculate and print the roots of a quadratic formula
   ! even if they are complex
   real    :: a, b, c ! coefficients
   complex :: z1, z2  ! roots
   real    :: discriminant
      a = 4.0
      b = 8.0
      c = 21.0
      call quadratic(a,b,c,z1,z2,discriminant) !  Calculate the roots
      if (abs(discriminant) < 0) then
         write(*,*) "the roots are real and equal:"
      else if (discriminant > 0) then
         write(*,*) "the roots are real:"
      else
         write(*,*) "the roots are complex:"
      end if
   !  Print the roots
      print *, "The roots(ie. x-intercepts)  are:"
      print *, "z1 =", z1
      print *, "z2 =", z2
   end program demo_quadratic


quadratic (3) October 17, 2020
Generated by manServer 1.08 from ff3e725a-1491-4e87-b2e0-eeca6037a883 using man macros.