Jeremy Knight Math 639 3/14/11 Fixed Point Algorithm Section 10.1 (algoritm 10.05) restart; Digits:=14; IiM5
<Text-field style="Heading 1" layout="Heading 1">FixedPt(n,G,xinitial,TOL,M,display)</Text-field> FixedPt:=proc(n,G,xinitial,TOL,M,display) #iterates multiple functions to find the location of a fixed point. #n=number of vars, G=array of functions for G={x1,x2,...,xn}, #x0= 1xn array for initial values, TOL=tolerance, M=max iterations local i,x,InfNorm, x1,x0,temp,k; #option trace; ###Subroutine section### InfNorm:=proc(n,v) local inf_norm,j: inf_norm:=v[1]: for j from 2 to n do if abs(v[j])>inf_norm then inf_norm:=abs(v[j]): end if: end do: return(inf_norm); end proc: ###End Subroutines### #Define x1 as x^k and x0 as x^(k-1) x0:=xinitial: x1:=Array(1..n): k:=1: while k<=M do temp:=Array(1..n); for i from 1 to n do temp[i]:=G[i](x0): end do: x1:=temp; if k>1 and InfNorm(n,(x1-x0))<TOL then print("fixed point:",x1); print("Iterations:",k): break: end if: if display=1 then print(k,x1): end if: k:=k+1: x0:=x1: end do: if k>M then print("Maximum number of iterations reached"); end if: end proc:
p:=evalf[20](Pi); g1:=(x::Array) -> ((1.0/3.0)*cos(x[2]*x[3])+1/6); g2:=(x::Array)-> (1.0/9)*sqrt(x[1]^2 + sin(x[3])+1.06)-0.1; g3:=(x::Array)-> (-1.0/20.0)*exp(-x[1]*x[2])-(10.0*evalf(Pi)-3.0)/60.0; G:=Array([g1,g2,g3]); JCI1JlFLeiplYEVmVEohIz4= Zio2IydJInhHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCYqKCQiIzUhIiIiIiIkIiNJRjBGMC1JJGNvc0c2JEYoSShfc3lzbGliR0YmNiMqJiY5JDYjIiIjRjEmRjs2IyIiJEYxRjFGMSNGMSIiJ0YxRiZGJkYm Zio2IydJInhHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCYqKCQiIzUhIiIiIiIiIipGMC1JJXNxcnRHNiRGKEkoX3N5c2xpYkdGJjYjLCgqJCY5JDYjRjEiIiNGMS1JJHNpbkdGNTYjJkY7NiMiIiRGMSQiJDEiISIjRjFGMUYxJEYxRjBGMEYmRiZGJg== Zio2IydJInhHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCYqKiEiIiIiIiQiIzVGLkYvJCIkKyNGLkYuLUkkZXhwRzYkRihJKF9zeXNsaWJHRiY2IywkKiYmOSQ2I0YvRi8mRjw2IyIiI0YvRi5GL0YvKiYsJiomJCIkKyJGLkYvLUkmZXZhbGZHRig2I0kjUGlHRihGL0YvJCIjSUYuRi5GLyQiJCsnRi5GLkYuRiZGJkYm LUkmQXJyYXlHJSpwcm90ZWN0ZWRHNiMvSSQlaWRHNiIiKlc+RmYj x0:=Array([0.1,0.1,-0.1]); FixedPt(3,G,x0,.00001,10,1); LUkmQXJyYXlHJSpwcm90ZWN0ZWRHNiMvSSQlaWRHNiIiKmN2alsj NiQiIiItSSZBcnJheUclKnByb3RlY3RlZEc2Iy9JJCVpZEc2IiIqV3RrWyM= NiQiIiMtSSZBcnJheUclKnByb3RlY3RlZEc2Iy9JJCVpZEc2IiIqcypbJVsj NiQiIiQtSSZBcnJheUclKnByb3RlY3RlZEc2Iy9JJCVpZEc2IiIqK2BrWyM= NiQiIiUtSSZBcnJheUclKnByb3RlY3RlZEc2Iy9JJCVpZEc2IiIqU1tLZiM= NiRRLWZpeGVkfnBvaW50OjYiLUkmQXJyYXlHJSpwcm90ZWN0ZWRHNiMvSSQlaWRHRiQiKiM+RCpbIw== NiRRLEl0ZXJhdGlvbnM6NiIiIiY=
<Text-field style="Heading 1" layout="Heading 1">FixedPt2(n,G,xinitial,TOL,M,display)</Text-field> FixedPt2:=proc(n,G,xinitial,TOL,M,display) #iterates multiple functions to find the location of a fixed point. #n=number of vars, G=array of functions for G={x1,x2,...,xn}, #x0= 1xn array for initial values, TOL=tolerance, M=max iterations local i,x,InfNorm, x1,x0,temp,k; #option trace; ###Subroutine section### InfNorm:=proc(n,v) local inf_norm,j: inf_norm:=v[1]: for j from 2 to n do if abs(v[j])>inf_norm then inf_norm:=abs(v[j]): end if: end do: return(inf_norm); end proc: ###End Subroutines### #Define x1 as x^k and x0 as x^(k-1) x0:=xinitial: x1:=Array(1..n): k:=1: while k<=M do temp:=x0; for i from 1 to n do temp[i]:=G[i](temp): end do: x1:=temp; if k>1 and InfNorm(n,(x1-x0))<TOL then print("fixed point:",x1); print("Iterations:",k): break: end if: if display=1 then print(k,x1): end if: k:=k+1: x0:=x1: end do: if k>M then print("Maximum number of iterations reached"); end if: end proc:
p:=evalf[20](Pi); g1:=(x::Array) -> ((1.0/3.0)*cos(x[2]*x[3])+1/6); g2:=(x::Array)-> (1.0/9)*sqrt(x[1]^2 + sin(x[3])+1.06)-0.1; g3:=(x::Array)-> (-1.0/20.0)*exp(-x[1]*x[2])-(10.0*evalf(Pi)-3.0)/60.0; G:=Array([g1,g2,g3]); JCI1JlFLeiplYEVmVEohIz4= Zio2IydJInhHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCYqKCQiIzUhIiIiIiIkIiNJRjBGMC1JJGNvc0c2JEYoSShfc3lzbGliR0YmNiMqJiY5JDYjIiIjRjEmRjs2IyIiJEYxRjFGMSNGMSIiJ0YxRiZGJkYm Zio2IydJInhHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCYqKCQiIzUhIiIiIiIiIipGMC1JJXNxcnRHNiRGKEkoX3N5c2xpYkdGJjYjLCgqJCY5JDYjRjEiIiNGMS1JJHNpbkdGNTYjJkY7NiMiIiRGMSQiJDEiISIjRjFGMUYxJEYxRjBGMEYmRiZGJg== Zio2IydJInhHNiJJJkFycmF5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