using LinearAlgebra, Plots
Copyright By PowCoder代写 加微信 powcoder
u” = \cos x^2,
x = range(0, 1; length=n)
h = step(x)
Δ = SymTridiagonal(fill(-2,n-2), fill(1,n-2))
f = x -> cos(x^2)
ũ = (Δ/h^2) \ [f(x[2]) – c₀/h^2; f.(x[3:end-2]); f(x[end-1]) – c₁/h^2]
u = [c₀; ũ; c₁]
scatter(x, u)
u_ex = x -> cos(x^2)
f = x -> -4x^2*cos(x^2) – 2sin(x^2)
function poisson_err(u_ex, f, n)
c₀ = u_ex(0)
c₁ = u_ex(1)
x = range(0, 1; length=n)
h = step(x)
Δ = SymTridiagonal(fill(-2,n-2), fill(1,n-2))
ũ = (Δ/h^2) \ [f(x[2]) – c₀/h^2; f.(x[3:end-2]); f(x[end-1]) – c₁/h^2]
u = [c₀; ũ; c₁] # computed solution to Possionn at grid
norm(u_ex.(x) – u, Inf)
ns = 10 .^ (1:7)
scatter(ns, poisson_err.(u_ex, f, ns); scale=:log10, yscale=:log10, label=”error”)
# we observe instability / ill-
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com