Jeremy Knight Math 639 Algorithm 11.4 Nonlinear Finite Difference restart;
<Text-field style="Heading 1" layout="Heading 1">NonlinearFiniteDiff</Text-field> To approximate the solution to the nonlinear boundary-value problem LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUkjbWlHRiQ2JVEjeSJGJy8lJ2l0YWxpY0dRJXRydWVGJy8lLG1hdGh2YXJpYW50R1EnaXRhbGljRictSSNtb0dGJDYtUSI9RicvRjNRJ25vcm1hbEYnLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y9LyUpc3RyZXRjaHlHRj0vJSpzeW1tZXRyaWNHRj0vJShsYXJnZW9wR0Y9LyUubW92YWJsZWxpbWl0c0dGPS8lJ2FjY2VudEdGPS8lJ2xzcGFjZUdRLDAuMjc3Nzc3OGVtRicvJSdyc3BhY2VHRkwtRiw2JVEiZkYnRi9GMi1JKG1mZW5jZWRHRiQ2JC1GIzYpLUYsNiVRInhGJ0YvRjItRjY2LVEiLEYnRjlGOy9GP0YxRkBGQkZERkZGSC9GS1EmMC4wZW1GJy9GTlEsMC4zMzMzMzMzZW1GJy1GLDYlUSJ5RidGL0YyRlpGXG8tRjY2LVEiJ0YnRjlGO0Y+RkBGQkZERkZGSC9GS1EsMC4xMTExMTExZW1GJy9GTkZpbkY5RjktRjY2LVEifkYnRjlGO0Y+RkBGQkZERkZGSEZobkZkb0Y5, for LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUkjbWlHRiQ2JVEiYUYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1JI21vR0YkNi1RJiZsZXE7RicvRjNRJ25vcm1hbEYnLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y9LyUpc3RyZXRjaHlHRj0vJSpzeW1tZXRyaW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hlbUYnLyUncnNwYWNlR0ZULUYsNiVRJyYjOTQ2O0YnL0YwRkVGPUY9 . NonlinearFiniteDiff:=proc(f,fy,fyp,A,B,alpha,beta,N,TOL,M) #f=f(x,y,y'); fy=df/dy ; fyp=df/dy' #A,B = endpoints #alpha, beta = boundary conditions #N = # of subintervals #TOL = tolerance #M = maximum iterations local a,b,c,d,k,i,t,w,h,L,x,z,u,v,temp,InfNorm,L2Norm: #option trace: InfNorm:=proc(n,x) local inf_norm,j: inf_norm:=x[1]: for j from 2 to n do if abs(x[j])>inf_norm then inf_norm:=abs(x[j]): end if: end do: return(inf_norm); end proc: L2Norm:=proc(n,x) local j,total; total:=0: for j from 1 to n do total:=total+x[j]^2: end do: return (total^(1.0/2.0)); end proc: a:=Array(1..N): b:=Array(1..N): c:=Array(1..N): d:=Array(1..N): u:=Array(1..N): v:=Array(1..N): w:=Array(1..N+2): #note: all indices for w are 1 greater than #textbooks indeces to accomodate Maple h:=(B-A)/(N+1): w[1]:=alpha: w[N+2]:=beta: for i from 1 to N do w[i+1]:=alpha+i*((beta-alpha)/(B-A))*h: end do: k:=1: while k<=M do x:=A+h: t:=(w[3]-alpha)/(2.0*h): temp:=Array([x,w[2],t]): a[1]:=2.0+(h^2)*fy(temp): b[1]:=-1+(h/2.0)*fyp(temp): d[1]:=(-1)*(2.0*w[2]-w[3]-alpha+(h^2)*f(temp)): for i from 2 to N-1 do x:=A+i*h: t:=(w[i+2]-w[i])/(2.0*h): temp:=Array([x,w[i+1],t]): a[i]:=2.0+(h^2)*fy(temp): b[i]:=-1.0+(h/2.0)*fyp(temp): c[i]:=-1.0-(h/2.0)*fyp(temp): d[i]:=(-1)*(2.0*w[i+1]-w[i+2]-w[i]+(h^2)*f(temp)): end do: x:=B-h: t:=(beta-w[N])/(2.0*h): temp:=Array([x,w[N+1],t]): a[N]:=2.0+(h^2)+fy(temp): c[N]:=-1.0-(h/2.0)*fyp(temp): d[N]:=(-1)*(2.0*w[N+1]-w[N]-beta+(h^2)*f(temp)): #Solve a tridiagonal linear system using the Crout Factorization Algorithm 6.7: L[1]:=a[1]: u[1]:=b[1]/a[1]: z[1]:=d[1]/L[1]: for i from 2 to N-1 do L[i]:=a[i]-c[i]*u[i-1]: u[i]:=b[i]/L[i]: z[i]:=(d[i]-c[i]*z[i-1])/L[i]: end do: L[N]:=a[N]-c[N]*u[N-1]: z[N]:=(d[N]-c[N]*z[N-1])/L[N]: v[N]:=z[N]: w[N+1]:=w[N+1]+v[N]: for i from N-1 to 1 by -1 do v[i]:=z[i]-u[i]*v[i+1]: w[i+1]:=w[i+1]+v[i]: end do: if InfNorm(N,v)<=TOL then for i from 0 to N+1 do x:=A+i*h: print(x,w[i+1]): end do: print("iterations:",k): break: end if: k:=k+1: end do: if k>M then print("Maximum iterations exceeded"): end if: end proc:
JSFH JSFH #define array w such that x=w[1] , y=w[2], y'=w[3] Digits:=20; f:=(p::Array)->1.0/8.0*(32.0+2.0*p[1]^3-p[2]*p[3]); fy:=(p::Array)->-1.0/8.0*p[3]; fyp:=(p::Array)->-1.0/8.0*(p[2]); IiM/ Zio2IydJInBHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmKigkIiM1ISIiIiIiJCIjISlGL0YvLCgkIiQ/JEYvRjAqJiQiIz9GL0YwKiQmOSQ2I0YwIiIkRjBGMComJkY7NiMiIiNGMCZGOzYjRj1GMEYvRjBGJkYmRiY= Zio2IydJInBHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCQqKCQiIzUhIiIiIiIkIiMhKUYwRjAmOSQ2IyIiJEYxRjBGJkYmRiY= Zio2IydJInBHNiJJJkFycmF5RyUqcHJvdGVjdGVkR0YmNiRJKW9wZXJhdG9yR0YmSSZhcnJvd0dGJkYmLCQqKCQiIzUhIiIiIiIkIiMhKUYwRjAmOSQ2IyIiI0YxRjBGJkYmRiY= NonlinearFiniteDiff(f,fy,fyp,1.0,3.0,17.0,43.0/3.0,19,10^(-8),100); NiQkIiM1ISIiJCIkcSJGJQ== NiQkIjUrKysrKysrKys2ISM+JCI1ZydIITNaYC1YdjohIz0= NiQkIjUrKysrKysrKys3ISM+JCI1TiM+ZFxfJ1I8eDkhIz0= NiQkIjUrKysrKysrKys4ISM+JCI1PiNRUGtOdW4mKlIiISM9 NiQkIjUrKysrKysrKys5ISM+JCI1JjQlUSo+Z2xIJ1E4ISM9 NiQkIjUrKysrKysrKys6ISM+JCI1L0kiZU41Q0Q5SCIhIz0= NiQkIjUrKysrKysrKys7ISM+JCI1PjFKZF1BUXZiNyEjPQ== NiQkIjUrKysrKysrKys8ISM+JCI1JilINC8oemlLKkg3ISM9 NiQkIjUrKysrKysrKys9ISM+JCI1NEokNDVrKUdsNzchIz0= NiQkIjUrKysrKysrKys+ISM+JCI1MlMkeXAxUSIpRz8iISM9 NiQkIjUrKysrKysrKys/ISM+JCI1KzouIz0+YSJ6Kj4iISM9 NiQkIjUrKysrKysrKytAISM+JCI1eiY9bCF5T1VyLTchIz0= NiQkIjUrKysrKysrKytBISM+JCI1eCx3LzMhKT41NjchIz0= NiQkIjUrKysrKysrKytCISM+JCI1SFEleW1qWy1YQSIhIz0= NiQkIjUrKysrKysrKytDISM+JCI1MSM9QScqZSQpUURDIiEjPQ== NiQkIjUrKysrKysrKytEISM+JCI1YTkqek9FUyUqW0UiISM9 NiQkIjUrKysrKysrKytFISM+JCI1ZEZqZCo9RSw4SCIhIz0= NiQkIjUrKysrKysrKytGISM+JCI1P2U6XTt2NmBAOCEjPQ== NiQkIjUrKysrKysrKytHISM+JCI1dkojbzd3XSlRYjghIz0= NiQkIjUrKysrKysrKytIISM+JCI1LCJSQmc5aC9GUiIhIz0= NiQkIjUrKysrKysrKytJISM+JCI1TExMTExMTExMOSEjPQ== NiRRLGl0ZXJhdGlvbnM6NiIiI28= NonlinearFiniteDiff2(f,fy,fyp,1.0,3.0,17.0,43.0/3.0,19,10^(-8),100); NiQkIiM1ISIiJCIkcSJGJQ== NiQkIjUrKysrKysrKys2ISM+JCI1ZydIITNaYC1YdjohIz0= NiQkIjUrKysrKysrKys3ISM+JCI1TiM+ZFxfJ1I8eDkhIz0= NiQkIjUrKysrKysrKys4ISM+JCI1PiNRUGtOdW4mKlIiISM9 NiQkIjUrKysrKysrKys5ISM+JCI1JjQlUSo+Z2xIJ1E4ISM9 NiQkIjUrKysrKysrKys6ISM+JCI1L0kiZU41Q0Q5SCIhIz0= NiQkIjUrKysrKysrKys7ISM+JCI1PjFKZF1BUXZiNyEjPQ== NiQkIjUrKysrKysrKys8ISM+JCI1JilINC8oemlLKkg3ISM9 NiQkIjUrKysrKysrKys9ISM+JCI1NEokNDVrKUdsNzchIz0= NiQkIjUrKysrKysrKys+ISM+JCI1MlMkeXAxUSIpRz8iISM9 NiQkIjUrKysrKysrKys/ISM+JCI1KzouIz0+YSJ6Kj4iISM9 NiQkIjUrKysrKysrKytAISM+JCI1eiY9bCF5T1VyLTchIz0= NiQkIjUrKysrKysrKytBISM+JCI1eCx3LzMhKT41NjchIz0= NiQkIjUrKysrKysrKytCISM+JCI1SFEleW1qWy1YQSIhIz0= NiQkIjUrKysrKysrKytDISM+JCI1MSM9QScqZSQpUURDIiEjPQ== NiQkIjUrKysrKysrKytEISM+JCI1YTkqek9FUyUqW0UiISM9 NiQkIjUrKysrKysrKytFISM+JCI1ZEZqZCo9RSw4SCIhIz0= NiQkIjUrKysrKysrKytGISM+JCI1P2U6XTt2NmBAOCEjPQ== NiQkIjUrKysrKysrKytHISM+JCI1dkojbzd3XSlRYjghIz0= NiQkIjUrKysrKysrKytIISM+JCI1LCJSQmc5aC9GUiIhIz0= NiQkIjUrKysrKysrKytJISM+JCI1TExMTExMTExMOSEjPQ== NiRRLGl0ZXJhdGlvbnM6NiIiI28= f:=(w::Array)->-(w[3])^2-w[2]+ln(w[1]); fy:=(w::Array)->-1; fyp:=(w::Array)->(-2)*w[3]; Zio2I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+JCI1enJIJlFHTiQ9QUUhIz8= NiQkIjUrKysrKysrKys5ISM+JCI1dkchZkcjb2A+akwhIz8= NiQkIjUrKysrKysrKys6ISM+JCI1J29tI1FdIlJySjAlISM/ NiQkIjUrKysrKysrKys7ISM+JCI1JylHdCRbYyIpKm8pcCUhIz8= NiQkIjUrKysrKysrKys8ISM+JCI1Lio0TysiPl84MGAhIz8= NiQkIjUrKysrKysrKys9ISM+JCI1ckUqKmUoZWdxcChlISM/ NiQkIjUrKysrKysrKys+ISM+JCI1VGE+cWdqaSR6VCchIz8= NiQkIjUrKysrKysrKys/ISM+JCI1VTRgJSpmMD1aSnAhIz8= NiRRLGl0ZXJhdGlvbnM6NiIiIic= JSFH