General roots of cubic polynomial with perturbed R

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.

@Justin,

Have you looked at this thread? That should give you an immediate starting point which you can use in conjunction with discussions in many texts on numerical methods.

1 Like

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.

I believe we already had a discussion in the thread Numerical resolution using cardan method. 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 (or downloadable via gist) 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

$ 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

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>

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.

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.

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

sudo apt-get install libblas-dev liblapack-dev

Thank you so much. :handshake: