# Question:combination of for-loop and while-loop..

## Question:combination of for-loop and while-loop..

Maple 14

Hi,

I wondered if you would be able to help.

I've set up a for-loop and while-loop that substitutes values of j and k into a given function

I want to get the answer for every right for example right[1], right[2]..but this code give the answer for right[1]nd right[6] only..

P := array([[1, 4], [2, 3], [3, 2], [4, 1], [6, 5], [6, 1], [6, 2], [5, 3]]);

j := 1; k := j+2; Fold := 0; Fnew := 1; counter := 0;

for i to 6 do j := i; k := j+2; while Fnew > Fold do Fold := Fnew; L[j, k] := evalf((P[k, 1]-P[j, 1])^2+(P[k, 2]-P[j, 2])^2)^(1/2); m[j, k] := (P[k, 1]-P[j, 1])/(P[k, 2]-P[j, 2]); a := m[j, k]; b := -1; c := P[j, 2]-m[j, k]*P[j, 1]; for i from j+1 to k-1 do e[i] := evalf(abs(a*P[i, 1]+b*P[i, 2]+c)/sqrt(a^2+b^2)); E[j, k] := sum(e[m], m = j+1 .. k-1) end do; Fnew := L[j, k]-E[j, k]; counter := counter +1; k := k+1 end do; right[j] := k-2 end do;

I want the loop run for j=1,k=3;j=2,k=4 and so on..but i still can't get the right answer..I don't know what else to do.

All help is greatly appreciated.

Thanks.

﻿