# Question:Help to Speed Up Code by Getting Rid of For Loops

## Question:Help to Speed Up Code by Getting Rid of For Loops

Maple

I am pretty new to Maple, but have used Matlab for a while....

I have a double for lop in my code that is slowing things down.....

I was thinking of speeding up the code with something like that below

NonDiagonal:= (n,m) → X(n,m) * (some function)

Diagonal:= (n)  → Y(n)*(some function)

DiagonalVector :=  seq(evalf(Diagonal(n-1)),n=1...N,1)

NonDiagonalMatrix := (not sure what to do here)

with(ArrayTools): Diag:=Diagonal(DigonalVector)

MyMatrix:= zip(`+`,NonDiagonal,Diag)

..............................

essentially I am just trying to replace the code below with something more effiicient as shown above

NonDiagonal:= (n,m) → X(n,m) * (some function)

Diagonal:= (n)  → Y(n)*(some function)

DiagonalVector :=  seq(evalf(Diagonal(n-1)),n=1...N,1)

for j to N do

for l to N do

if l = j then

MyMatrix[l, j] := DiagonalVector[l]

else MyMatrix[j, l] := evalf(simplify(NonDiagonal(j-1, l-1)))

end if

end do

end do

﻿