44 Reputation

18 years, 131 days

Algorithm L...

Dear Joe,

thank you for your nice algorithm L which exactly does what I asked for!

All the best

Thomas

Algorithm L...

Dear Joe,

thank you for your nice algorithm L which exactly does what I asked for!

All the best

Thomas

Passing all the B[i,j] used by the 'W' r...

Dear Allan, thank you for your detailed explanation! Now I understand the mechanism. In particular many thanks for your nice program dproc. It works fine. I could introduce dependencies on the B[i,k] as desired. dproc is an excellent contribution to MaplePrimes. All the best, Thomas

Passing all the B[i,j] used by the 'W' r...

Dear Allan, thank you for your detailed explanation! Now I understand the mechanism. In particular many thanks for your nice program dproc. It works fine. I could introduce dependencies on the B[i,k] as desired. dproc is an excellent contribution to MaplePrimes. All the best, Thomas

An example for the W(i,k,j,l)...

Dear Allan, thank you for your response! I have tried several ways to pass the indeterminate functions B[i,k] to the subroutine W which calculates the transition probability. All attempts failed. For example, I tried DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k,B)*B[j,l](t)-W(i,k,j,l,B)*B[i,k](t),l=1..N),j=1..N),k=1..N),i=1..N); You will find the corresponding subroutine below. Other attempts were DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k,B[j,l],B[i,k])*B[j,l](t)-W(i,k,j,l,B[i,k],B[j,l])*B[i,k](t),l=1..N),j=1..N), k=1..N),i=1..N); or DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k)*B[j,l](t)-W(i,k,j,l)*B[i,k](t),l=1..N),j=1..N),k=1..N),i=1..N); with a global command within W: W := proc(i::integer, k::integer, j::integer, l::integer) global B; ... etc ... I have not tried to code the W(i,k,j,l,B) in direct manner into the DGLS command, because the dependencies are too complicated. Therefore I want to use a subroutine call. Thank you, Thomas W := proc(i::integer, k::integer, j::integer, l::integer, B) # 30.10.2005 # An example for the calculation of the transition probability *** W ***. # This example just outlines the programming mechanism, its physical meaning is void. # If one uses *** W *** in the following Maple command: #DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k,B)*B[j,l](t)-W(i,k,j,l,B)*B[i,k](t),l=1..N),j=1..N),k=1..N),i=1..N); # then one gets error messages from *** W *** and a subsequent dsolve command does not give any result. # As I understand: The indeterminate functions *** B[i,k] *** are not passed to *** W *** as functions. # What *** W *** actually receives is a string like "B_1_2" but not a function. # "W: B[i,k], B[j,l] =", B[1, 1], B[1, 1] # "W: An error has occured!" # "Last activity: ", "Initialisation!" # ... and so on ... # However, when ** W *** is called from the test procdure *** test_w *** # (which is appended to *** W ***, see below), # then *** W *** returns a transition probability (W = 1/2) as expected: # test_w(); # "W: B[i,k], B[j,l] =", 2, 1 # "W: WTransition", 1/2 # "i, ,k ,j l, W(i,k,j,l):", 1, 1, 2, 1, 1/2 local itest, WTransition, NMin, NMax, NKrit_jl, Report; global N, ModelForProbability, Flag; try # Initialise. Report := "Initialisation!"; # Set *** itest *** = 1 for debugging only! itest := 1; if i <= 0 or i > N or j <= 0 or j > N or k <= 0 or k > N or l <= 0 or l > N or N <= 0 then return undefined; fi; # Test: Has *** B *** been passed to *** W *** correctly? if itest = 1 then print("W: B[i,k], B[j,l] =",B[i,k], B[j,l]); fi; WTransition := 0; # Calculate *** WTransition ***. if B[i,k] > 1 then WTransition := 1/2; else WTransition := 0; end if; # Check the result and return. if WTransition < 0 or WTransition > 1 then print("W: Invalid transition probability! Must be >= 0 and <= 1!"); return undefined; fi; if itest = 1 then print("W: WTransition",WTransition); end if; return WTransition; catch : print("W: An error has occured!"); Flag := "An error!"; print("Last activity: ",Report) end try; end proc; test_w := proc() # Use *** test_w *** to test procedure *** W ***. global N, ModelForProbability, Flag; local i,k,j,l,B_Test, dummy1, dummy2; N := 12; ModelForProbability := 1; for dummy1 from 1 to N do for dummy2 from 1 to N do B_Test[dummy1,dummy2] := 0; end do; end do; i := 1; k := 1; j := 2; l := 1; B_Test[i,k] := 2; B_Test[j,l] := 1; print("i, ,k ,j l, W(i,k,j,l):",i,k,j,l,W(i,k,j,l,B_Test)); end proc;

An example for the W(i,k,j,l)...

Dear Allan, thank you for your response! I have tried several ways to pass the indeterminate functions B[i,k] to the subroutine W which calculates the transition probability. All attempts failed. For example, I tried DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k,B)*B[j,l](t)-W(i,k,j,l,B)*B[i,k](t),l=1..N),j=1..N),k=1..N),i=1..N); You will find the corresponding subroutine below. Other attempts were DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k,B[j,l],B[i,k])*B[j,l](t)-W(i,k,j,l,B[i,k],B[j,l])*B[i,k](t),l=1..N),j=1..N), k=1..N),i=1..N); or DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k)*B[j,l](t)-W(i,k,j,l)*B[i,k](t),l=1..N),j=1..N),k=1..N),i=1..N); with a global command within W: W := proc(i::integer, k::integer, j::integer, l::integer) global B; ... etc ... I have not tried to code the W(i,k,j,l,B) in direct manner into the DGLS command, because the dependencies are too complicated. Therefore I want to use a subroutine call. Thank you, Thomas W := proc(i::integer, k::integer, j::integer, l::integer, B) # 30.10.2005 # An example for the calculation of the transition probability *** W ***. # This example just outlines the programming mechanism, its physical meaning is void. # If one uses *** W *** in the following Maple command: #DGLS:=seq(seq(diff(B[i,k](t),t)=add(add(W(j,l,i,k,B)*B[j,l](t)-W(i,k,j,l,B)*B[i,k](t),l=1..N),j=1..N),k=1..N),i=1..N); # then one gets error messages from *** W *** and a subsequent dsolve command does not give any result. # As I understand: The indeterminate functions *** B[i,k] *** are not passed to *** W *** as functions. # What *** W *** actually receives is a string like "B_1_2" but not a function. # "W: B[i,k], B[j,l] =", B[1, 1], B[1, 1] # "W: An error has occured!" # "Last activity: ", "Initialisation!" # ... and so on ... # However, when ** W *** is called from the test procdure *** test_w *** # (which is appended to *** W ***, see below), # then *** W *** returns a transition probability (W = 1/2) as expected: # test_w(); # "W: B[i,k], B[j,l] =", 2, 1 # "W: WTransition", 1/2 # "i, ,k ,j l, W(i,k,j,l):", 1, 1, 2, 1, 1/2 local itest, WTransition, NMin, NMax, NKrit_jl, Report; global N, ModelForProbability, Flag; try # Initialise. Report := "Initialisation!"; # Set *** itest *** = 1 for debugging only! itest := 1; if i <= 0 or i > N or j <= 0 or j > N or k <= 0 or k > N or l <= 0 or l > N or N <= 0 then return undefined; fi; # Test: Has *** B *** been passed to *** W *** correctly? if itest = 1 then print("W: B[i,k], B[j,l] =",B[i,k], B[j,l]); fi; WTransition := 0; # Calculate *** WTransition ***. if B[i,k] > 1 then WTransition := 1/2; else WTransition := 0; end if; # Check the result and return. if WTransition < 0 or WTransition > 1 then print("W: Invalid transition probability! Must be >= 0 and <= 1!"); return undefined; fi; if itest = 1 then print("W: WTransition",WTransition); end if; return WTransition; catch : print("W: An error has occured!"); Flag := "An error!"; print("Last activity: ",Report) end try; end proc; test_w := proc() # Use *** test_w *** to test procedure *** W ***. global N, ModelForProbability, Flag; local i,k,j,l,B_Test, dummy1, dummy2; N := 12; ModelForProbability := 1; for dummy1 from 1 to N do for dummy2 from 1 to N do B_Test[dummy1,dummy2] := 0; end do; end do; i := 1; k := 1; j := 2; l := 1; B_Test[i,k] := 2; B_Test[j,l] := 1; print("i, ,k ,j l, W(i,k,j,l):",i,k,j,l,W(i,k,j,l,B_Test)); end proc;
 Page 1 of 1
﻿