plz. help to convert this fortran iv program into matlab programm .I wrote the code for subroutine.

DIMENSION Y(6),DY(6),ETAEND(4),TEST(4)
DOUBLE PRECISION Y,DY,H,ETA,X,B
EXTERNAL DIFF
COMMON B
1 READ (5,101) H,X,B,DELPR,ETEST
READ (5,102) N,(ETAEND(I),TEST(I),I = 1,N)
2 WRITE (6,201) H,B
I=1
3 PRINT = DELPR
ETA = O.000
Y(1) = 0.000
Y(2) = O.000
Y(3) = x
Y(4) = 0eODO
Y(5) = O.0000
Y(6) = 1.000
CALL ADAMS(6,H,ETA,O,Y,DY,l,DIFF)
WRITE (6,202) ETA*Y(l),Y(2),Y(3)
4 CALL ADAMS(6,H,ETA,1,Y,DYI,1,DIFF)
IF(ETA.LT.PR1NT) GO TO 6
PRINT = PRINT + DELPR
5 WRITE (6,202) ETA,Y(l),Y(2),Y(3)
6 IF(ETA.LT.ETAEND(I)) GO TO 4
7 DELX = (Y(5)*(1.000 -Y(2))-Y(6)*Y(3))/(Y(5)**2 + Y(6)**2)
E = (1.O00 - Y(2)**2 ) + Y(3)**2
x = x + DELx
9 IF(ABS(DELX/X).GT.TEST(I)) GO TO 3
10 IF(E.LT.ETEST) GO TO 12
11 IF(I.EQ.N) STOP
I = I+1
GO TO 3
12 WRITE (6,203) E
13 READ (5,103) B
WRITE (6,201) H,B
GO TO 3
101 FORMAT (2D10.O,D20.0,2E10.00)
102 FORMAT (I2,/,(2E10.0))
103 FORMAT (D20.0)
201 FORMAT (3HlH=,D16.8,5X,2HB=,D20.10)
202 FORMAT (4D25.8)
203 FORMAT (3HE=,E16.8)
END
C SUBROUTINE TO COMPUTE THE DIFFERENTIAL EQUATIONS
SUBROUTINE DIFF(ETA,Y,DY)
DIMENSION Y(l),DY(l)
DOUBLE PRECISION ETA,Y,DY,B
COMMON B
DY(1) = Y(2)
DY(2) = Y(3)
DY(3) = -Y(l)*Y(3) + B*(Y(2)**2-1.000)
DY(4) = Y(5)
DY(5) = Y(6)
DY(6) = -(Y(4)*Y(3)+Y(l)*Y(6)) + 2.000*B*Y(2)*Y(5)
RETURN
END
matlab code for subroutine :
function dy = mabc(n,y)
dy = zeros(6,1); % a column vector
beta = 1;
dy(1) = y(2);
dy(2) = y(3);
dy(3) = - (y(1)*y(3)) + (beta *(y(2)^2) - 1);
dy(4) = y(5);
dy(5) = y(6);
dy(6) = -(y(1)*y(6) + y(3)*y(4)) + (2*beta*y(2)*y(5));
end

3 Comments

It looks to me as if you should not bother to convert the code as such, and that instead you should rewrite the code in terms of ode45() .
That "FORTRAN IV" code is also perfectly valid Fortran 95 or F2003. It's actually F77, as the F66 interpretation of EXTERNAL isn't compatible with F77.
What "EXTERNAL" does here is tell the compiler the routine is to allow a procedure name to be used as a dummy argument. In F66, the EXTERNAL statement overlaid F77-introduced INTRINSIC; that's the incompatibility w/ F77. It has no bearing on how results are returned--as with all SUBROUTINEs, the arguments are the mechanism by which variables are modified so that's no great issue.
In the F66 interpretation, the dummy name is declared to be an external FUNCTION name which name can then be used as an actual argument to a subprogram. The name becomes the place holder for the returned value from the function in the CALL statement. F66 functions could not return arrays as needed here; hence the code must be F77+ for EXTERNAL to have the proper behavior.
But, all the details of the Fortran aside; overall, the best bet is probably Walter's advice if there's need to actually move from Fortran to Matlab.
You did the subroutine so why can't you do the rest? It's only a few dozen lines. If you had started on it when you posted it, you'd be done now ! Instead you're waiting for us to do it for you. Or was there one particular syntax that you don't know how to do in MATLAB?

Sign in to comment.

Answers (0)

Categories

Asked:

on 23 Mar 2014

Edited:

dpb
on 24 Mar 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!