INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Goto in pascal to Matlab

Goto in pascal to Matlab

(OP)
Does anyone know how to convert this program from pascal to matlab?  The goto statement is really confusing me.  I just don't understand how it flows with the goto statements in there. If going to matlab cannot be explained , if I could get an explanation of what exactly this program is doing that would be great.   I would really appreciate it.

Thanks, Tina

Bhigh:= 1.5E+11;
        Blow := 1.5E+2;
    100:
    B := (Bhigh + Blow)/2.0;
    w[1] := Ts;  {Surface Temperature}
    w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope}  
    y := 0.0;
    repeat
        If w[1] > 1.0 then begin
            Blow := B;
            goto 100;
        end;
        If w[2] < 0.0 then begin
            Bhigh := B;
            goto 100;
        end;
        
        Runge( Equations0, 2, 0.01, y, w );
        {writeln(B:25:20,y:10:5);}
    until Bhigh-Blow < 0.00000005;

RE: Goto in pascal to Matlab

I really don't know Matlab, but I might be able to help you understand this.  The goto statement says in the code to go to the point of the specified label.  When it says "goto 100", it is saying to "go to the point in the code where the label named 100 appears".

Upon web search, my best guess is that Matlab doesn't support goto.  As far as adapting it goes, you would probably need to supply a little more about what this code is supposed to do, along with acceptable & expected data, so any suggestion we might give you on a gotoless code could be tested.

(and yes, goto is one of the things I tend to loathe, especially in this kind of case)

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy"

RE: Goto in pascal to Matlab

You need to rewrite it without a goto first, then translate.  
First declare a boolean variable, say goto100

The code will look something like

CODE

Bhigh:= 1.5E+11;
Blow := 1.5E+2;
repeat
    B := (Bhigh + Blow)/2.0;
    w[1] := Ts;  {Surface Temperature}
    w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope}  
    y := 0.0;
    goto100 := false;
    repeat
        If w[1] > 1.0 then begin
            Blow := B;
            goto100 := true;
        end
        else If w[2] < 0.0 then begin
            Bhigh := B;
            goto100 := true;
        end
        else begin
           Runge( Equations0, 2, 0.01, y, w );
           {writeln(B:25:20,y:10:5);}
        end;
    until goto100 or Bhigh-Blow < 0.00000005;
until not goto100;
Could you translate that to Matlab?  Like Glen999, I don't know Matlab either.

RE: Goto in pascal to Matlab

Quote (me):


As far as adapting it goes, you would probably need to supply a little more about what this code is supposed to do, along with acceptable & expected data

I realized in reading this that it might sound daunting to you.  What I meant was to maybe supply the full Pascal program, along with some idea of what the program does (i.e. calculates the Pygathorean theorem for input).  I'm sure you know what it should do (and maybe have the EXE of this somewhere even), since you are wanting to do something with it in Matlab.

Most of us are Pascal-only people but can definitely help you, at least in terms of expressing the algorithm in constructs that Matlab allows.  But we would need to be able to fully understand it in order to do that.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy"

RE: Goto in pascal to Matlab

I thing Matlab has only while- and for-loop
 

RE: Goto in pascal to Matlab

IMHO

CODE

Runge( Equations0, 2, 0.01, y, w );
could be for finding of solution w of initial value problem for system of 2 differential equations with right hand side y, integration step 0.01 and with the initial values

CODE

w[1] := Ts;  {Surface Temperature}
w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope}  
 

RE: Goto in pascal to Matlab

I don't understand the purpose of the program, but IMHO your original code with goto and repeat-until loop

CODE

Bhigh:= 1.5E+11;
Blow := 1.5E+2;
100:
B := (Bhigh + Blow)/2.0;
w[1] := Ts;  {Surface Temperature}
w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope}  
y := 0.0;
repeat
  If w[1] > 1.0 then begin
    Blow := B;
    goto 100;
  end;
  If w[2] < 0.0 then begin
    Bhigh := B;
    goto 100;
  end;
  Runge( Equations0, 2, 0.01, y, w );
  {writeln(B:25:20,y:10:5);}
until Bhigh-Blow < 0.00000005;
could be approximately transformated into this code with only one while-loop (which could you then recode in Matlab)

CODE

Bhigh:= 1.5E+11;
Blow := 1.5E+2;
{* before the loop:}
{* reset values *}
B := (Bhigh + Blow)/2.0;
w[1] := Ts;  {Surface Temperature}
w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope}  
y := 0.0;
{****************}
while Bhigh-Blow >= 0.00000005 begin
  if (w[1] > 1.0) or (w[2] < 0.0) then begin
    If w[1] > 1.0 then Blow  := B; {adjust new interval to <B, Bhigh>}
    If w[2] < 0.0 then Bhigh := B; {adjust new to <Blow, B>}
    {* reset values *}
    B := (Bhigh + Blow)/2.0;
    w[1] := Ts;  {Surface Temperature}
    w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope}  
    y := 0.0;
    {****************}
  end;
  Runge( Equations0, 2, 0.01, y, w );
end {while}
But note, that the repeat-until loop checks the condition at end, but the while-loop checks the condition at the beginning of the loop. So the repeat-loop in your original code will surely be executed minimal one time, but the while-loop in the transformed code will be executed minimal one time only if the condition Bhigh-Blow >= 0.00000005 is fullfilled before the first iteration - in your case it's true.
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close