# General roots of cubic polynomial with perturbed R

**URL:** <https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423>\
**Category:** Uncategorized\
**Created:** [November 17, 2020, 9:31pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423 "2020-11-17T21:31:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://fortran-lang.discourse.group/u/Justin)\
**Post date:** [November 17, 2020, 9:31pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/1 "2020-11-17T21:31:57Z")

</div>

Good evening dear everyone, how are you doing in this good discussion forum ? I think this article finds you well. I need a Fortran code that can allow me to numerically determine the roots of a polynomial of degree 3 with coefficients disturbed by an R parameter. I want all the roots to be saved in an output file in order to l 'use to plot the curve of the real parts against the imaginary parts. I have already tried with the various FORTRAN programs which are in the preceding discussions but I could not. Please help me.  
You can use the example ax3 + (b + R)x2 + cx + (R-d)x = 0 by choosing values ​​for a, b, c and d.  
R varies between 0 and 25. And I will adapt it to what I have at my disposal.

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [November 17, 2020, 9:51pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/2 "2020-11-17T21:51:27Z")

</div>

@Justin,

Have you looked at this [**thread**](https://fortran-lang.discourse.group/t/cardanos-solution-of-the-cubic-equation/111)? That should give you an immediate starting point which you can use in conjunction with discussions in many texts on numerical methods.

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://fortran-lang.discourse.group/u/Justin)\
**Post date:** [November 18, 2020, 12:36pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/3 "2020-11-18T12:36:05Z")

</div>

Yes, but it displays error during compilation. So I tried using the code sent by _@Ivanpribec_, but there is not subroutine get\_command\_argument(k,num) and sgeev(‘N’,‘N’,n,M,n, wr,…). What causes it to display can also be wrong.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [November 18, 2020, 9:11pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/4 "2020-11-18T21:11:49Z")

</div>

I believe we already had a discussion in the thread [Numerical resolution using cardan method](https://fortran-lang.discourse.group/t/numerical-resolution-using-cardan-method/344). Next time, please post any further questions there to preserve the discussion in a single place.

I just tested the solution based upon the polynomial companion matrix posted [ḣere](https://fortran-lang.discourse.group/t/cardanos-solution-of-the-cubic-equation/111/5) (or downloadable via [gist](https://gist.github.com/ivan-pi/975b0765bb7430e502bb29792bd1f507)) using gfortran 5.5 and it works fine. Can you post the error you get during compilation?

PS: you can enclose your error output in brackets like this

````
```text
$ gfortran-5 -Wall polynomial_companion_matrix.f90 -llapack
/usr/bin/ld: warning: libgfortran.so.4, needed by /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/liblapack.so, may conflict with libgfortran.so.3
```

````

to make it show up as follows

```nohighlight
$ gfortran-5 -Wall polynomial_companion_matrix.f90 -llapack
/usr/bin/ld: warning: libgfortran.so.4, needed by /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/liblapack.so, may conflict with libgfortran.so.3

```

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://fortran-lang.discourse.group/u/Justin)\
**Post date:** [November 19, 2020, 9:14pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/5 "2020-11-19T21:14:59Z")

</div>

See the error on this picture

 ![IMG_20201119_223623_9](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/730685003df50fc10412605d82937a28afe91e24.jpeg)

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [November 20, 2020, 4:54am UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/6 "2020-11-20T04:54:35Z")

</div>

> [@Justin](#):
>
> See the error on this picture

What is your compiler version? I’m under the impression gfortran has long supported the format descriptors you show:

> C:\Temp\>type p.f90  
> integer :: n = 42  
> write( \*, “(A,I0,A)” ) "Hello World! “, n, " is the answer to everything!”  
> end
> 
> C:\Temp\>gfortran --version -Wall -std=f2018 p.f90 -o p.exe  
> GNU Fortran (GCC) 10.0.1 20200209 (experimental)  
> Copyright (C) 2020 Free Software Foundation, Inc.  
> This is free software; see the source for copying conditions. There is NO  
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> C:\Temp\>p.exe  
> Hello World! 42 is the answer to everything!
> 
> C:\Temp\>

---

<div class="post-metadata">

**Author:** ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)\
**Post date:** [November 20, 2020, 9:20am UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/7 "2020-11-20T09:20:06Z")

</div>

> [@Justin](#):
>
> See the error on this picture

Hi @Justin, it looks like you have the capital letter `"O"` instead of the number `"0"` in your format string - this would cause the error you are seeing. You will notice that in your (Ubuntu?) terminal the number `"0"` is displayed with a dot inside to indicate the difference.

Edit: unfortunately, depending on your operating system, you will not see the difference between `"O"` and `"0"` on this Discourse.

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://fortran-lang.discourse.group/u/Justin)\
**Post date:** [November 20, 2020, 10:35am UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/8 "2020-11-20T10:35:05Z")

</div>

Thank you all for your contributions. After correcting the error, here is what is displayed now (see photo). I think “ **LAPACK routine xgeev** ” is missing in the code.

 ![IMG_20201120_112127_9.jpg](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/314be75cebd7e49be2cae1af6d6d618d63d29adf.jpeg)

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [November 20, 2020, 11:36am UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/9 "2020-11-20T11:36:19Z")

</div>

It looks like you don’t have LAPACK installed. On Ubuntu you can install LAPACK and BLAS using the following command:

```nohighlight
sudo apt-get install libblas-dev liblapack-dev

```

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://fortran-lang.discourse.group/u/Justin)\
**Post date:** [November 20, 2020, 4:51pm UTC](https://fortran-lang.discourse.group/t/general-roots-of-cubic-polynomial-with-perturbed-r/423/10 "2020-11-20T16:51:52Z")

</div>

Thank you so much. 🤝
