Has anyone any idea about it?

if i read it as character, there seem no way to convert into mathematical expression in fortran code. It stays as character.

Has anyone any idea about it?

if i read it as character, there seem no way to convert into mathematical expression in fortran code. It stays as character.

For more complete information about compiler optimizations, see our Optimization Notice.

What do you mean by "convert into mathematical expression"? There is no intrinsic variable type in Fortran called "mathematical expression" or endowed with the usual expected properties of mathematical expressions.

Are you trying to program a calculator in Fortran? Be aware that this has been done several times, but it is by no means simple to do.

Is this part of a computer science test problem? e.g. write a Fortran program to parse equations.

Jim Dempsey

Hi guy, I'm trying to write a program to conduct regression (or curve-fitting), I could not convert the read character into statement useable in Fortran . My problem as below:

subroutine set_eqn_and_initial_val1

use mod_share_GNA1

implicit none

character(999)::scha1

real(kind=srk)::y,m,x,c

open(unit=1000,file='data_input\\eqn_and_initial_value.txt',status='old',action='read')

read(1000,*)scha1

write(*,*)scha1

y=real(trim(scha1)) <===== this statement is wrong. Could someone help me to move forward?

close(unit=1000)

end subroutine set_eqn_and_initial_val1

You might like to look up this:

!------- -------- --------- --------- --------- --------- --------- --------- -------

! Fortran 90 function parser v1.1

!------- -------- --------- --------- --------- --------- --------- --------- -------

!

! This function parser module is intended for applications where a set of mathematical

! fortran-style expressions is specified at runtime and is then evaluated for a large

! number of variable values. This is done by compiling the set of function strings

! into byte code, which is interpreted efficiently for the various variable values.

!

! The source code is available from http://fparser.sourceforge.net

!

! Please send comments, corrections or questions to the author:

! Roland Schmehl <roland.schmehl@alumni.uni-karlsruhe.de>

!

!------- -------- --------- --------- --------- --------- --------- --------- -------

! The function parser concept is based on a C++ class library written by Juha

! Nieminen <warp@iki.fi> available from http://warp.povusers.org/FunctionParser/

**Quote:**

Eng Giap G.wrote:character(999)::scha1

open(unit=1000,file='data_input\\eqn_and_initial_value.txt',status='old',action='read')

read(1000,*)scha1

y=real(trim(scha1)) <===== this statement is wrong. Could someone help me to move forward?

The function REAL cannot be applied to character type arguments.

To answer your question regarding moving forward, we need to know the contents of the file.

If you are satisfied with fitting only linear expressions or polynomials, it would be enough to structure the input data accordingly.

Linear regression does not require trial values of the fit coefficients.

Writing an expression parser(or even adopting an existing one) is probably an overkill for your needs. Please explain what you want your program to do, and remember that Fortran is a compiled language.

You could take a look at the code available at the NIST GAMS (Guide to Available Mathematical Software) site:

Use the key word search for terms such as "linear regression" or "curve fit" to see the available subroutines. Maybe a routine will fit your need, or at least provide examples.

Regards, Greg

The following Fortran program uses MKL/Lapack-95 GELS to obtain the least squares polynomial to fit input x,y data. The first line of the data file contains the degree and the number of input data pairs. The subsequent lines contain (x(i),y(i), i = 1, m) data.

program polyfit use lapack95, only : gels implicit none double precision, allocatable :: x(:),y(:,:),c(:),A(:,:) integer :: i,j,m,n,info read(*,*)n,m ! degree and number of data pairs allocate(x(m),y(m,1),c(n+1)) read(*,*)(x(i),y(i,1),i=1,m) ! data pairs allocate(A(m,n+1)) A(:,1) = 1d0 do j=2,n+1 A(:,j) = A(:,j-1)*x end do call gels(A,y,'N',info) if(info /= 0)then write(*,*)'*** INFO = ',info,' FROM GELS' stop endif c=y(1:n+1,1) ! coefficients of polynomial write(*,10)(i,c(i),i=1,n+1) 10 format(I3,2x,ES12.4) end program polyfit

Sample data file:

1,3 1,4.01 2,5.49 3,6.95

Program results (coefficients):

1 2.5433E+00 2 1.4700E+00

Rate Us