Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development Tools (Compilers, Debuggers, Profilers & Analyzers)
- Intel® Fortran Compiler
- Read from a .txt file a character equation "y=m*x+c" and convert it into mathematical expression in Fortran code

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##
Read from a .txt file a character equation "y=m*x+c" and convert it into mathematical expression in Fortran code

Eng_Giap_G_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
07:25 AM

18 Views

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.

11 Replies

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
12:37 PM

18 Views

What do you mean by "convert

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.

Highlighted
##

jimdempseyatthecove

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
01:13 PM

18 Views

Is this part of a computer

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

Jim Dempsey

Highlighted
##

Eng_Giap_G_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
06:44 PM

18 Views

Hi guy, I'm trying to write a

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

Highlighted
##

DavidWhite

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
06:49 PM

18 Views

You might like to look up

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/

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
07:32 PM

18 Views

Quote:Eng Giap G. wrote:

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.

Highlighted
##

gib

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017
07:37 PM

18 Views

It looks to me as if he

It looks to me as if he simply wants to do linear regression on a set of points.

Highlighted
##

Greg_T_

New Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-31-2017
07:22 AM

18 Views

You could take a look at the

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

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-31-2017
09:44 AM

18 Views

The following Fortran program

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

Highlighted
##

gib

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-31-2017
03:47 PM

18 Views

This might be an assignment -

This might be an assignment - I'm not sure that we should do students' assignments for them.

Highlighted
##

I agree, but one would hope that if this is a homework problem the instructor would have stipulated that the student must include a verbal description of the underlying linear algebra and an explanation of how the code implements the underlying algorithm.

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-31-2017
04:49 PM

18 Views

I agree, but one would hope

Highlighted
##

Hi, guys, thanks for helping out. I will look into all the recommendation and suggestion. This is not a student assignment. I am a researcher and I'm trying to code to solve a scientific problem. The solution of the problem would most likely end up in the hand of researchers like field biologist (environmentalist) who has limited access to expensive software, and also the ability to customize equation to fit their needs and data management to save time. Thanks again for all those who are helping out. This would also help others encountering a similar problem.

Eng_Giap_G_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-04-2017
07:40 AM

18 Views

Hi, guys, thanks for helping