Student Support Forum: 'Function automatically created by a loop' topicStudent Support Forum > General > "Function automatically created by a loop"

 Next Comment > Help | Reply To Topic
 Author Comment/Response Frederic 03/31/10 08:50am Hi, I have a problem and just can't find a way to solve this in a nice way! What I want to do is to have a function defined with different parameters for different region. I've been doing this with conditionals and it works fine: mode[z_] := (-valuesbeta2[[Length[valuesbeta2] + 1 - i]]/(n1^2))*(A1* Exp[-p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n1]*(z - 0)] + B1* Exp[p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n1]*(z - 0)]) /; (-2 <= z && z <= 0); mode[z_] := (-valuesbeta2[[Length[valuesbeta2] + 1 - i]]/(n2^2))*(A2* Exp[-p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n2]*(z - 0)] + B2* Exp[p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n2]*(z - 0)]) /; (0 <= z && z <= z1); mode[z_] := (-valuesbeta2[[Length[valuesbeta2] + 1 - i]]/(n3^2))*(A3* Exp[-p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n3]*(z - z1)] + B3* Exp[p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n3]*(z - z1)]) /; (z1 <= z && z <= z2); mode[z_] := (-valuesbeta2[[Length[valuesbeta2] + 1 - i]]/(n4^2))*(A4* Exp[-p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n4]*(z - z2)] + B4* Exp[p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], n4]*(z - z2)]) /; (z2 <= z && z <= z3); But instead of just manually inserting a new line of code für every region z4, z5, z6... I wanted do do this function definition in a For loop...the problem is, that this doesn't work, it just seems to overwrite the function definition with the new one...but it works when the lines are inserted manually like above! I dont understand this...hiere is the loop I was trying to do, some help would be very appreciated! For[h = 5, h < 2*r + 2, h++, mode[z_] := (-valuesbeta2[[ Length[valuesbeta2] + 1 - i]]/(ToExpression[ "n" <> ToString[h]]^2))*(ToExpression["A" <> ToString[h]]* Exp[-p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], ToExpression["n" <> ToString[h]]]*(z - ToExpression["z" <> ToString[h - 2]])] + ToExpression["A" <> ToString[h]]* Exp[p[valuesbeta2[[Length[valuesbeta2] + 1 - i]], ToExpression["n" <> ToString[h]]]*(z - ToExpression["z" <> ToString[h - 2]])]) /; (ToExpression[ "z" <> ToString[h - 2]] <= z && z <= ToExpression["z" <> ToString[h - 1]]); ]; URL: ,

 Subject (listing for 'Function automatically created by a loop') Author Date Posted Function automatically created by a loop Frederic 03/31/10 08:50am Re: Function automatically created by a loop Nasser M. Ab... 04/01/10 10:04pm
 Next Comment > Help | Reply To Topic