Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Modify task8 (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleo-53 committed Apr 30, 2024
1 parent 9568008 commit 6554e11
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
Binary file modified task7/8-CollocationCheb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified task7/8-CollocationRand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 25 additions & 18 deletions task7/collocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ func getChebNodes(n int) []float64 {

func getWCol(n int, alpha1, alpha2, beta1, beta2 float64) []Funct {
res := make([]Funct, n)
// res[0] = Funct{func(x float64) float64 {
// A := mat.NewDense(2, 2, []float64{(-alpha1 - alpha2), alpha1, (beta1 + beta2), beta1})
// B := mat.NewVecDense(2, []float64{(-alpha1 - 2.0*alpha2), (-beta1 - 2.0*beta2)})
// C := mat.NewVecDense(2, nil)
// C.SolveVec(A, B)
// return x*x + C.AtVec(0)*x + C.AtVec(1)
// }}
// res[1] = Funct{func(x float64) float64 {
// A := mat.NewDense(2, 2, []float64{-alpha1, (alpha1 - alpha2), beta1, (beta1 + beta2)})
// B := mat.NewVecDense(2, []float64{(alpha1 + 3.0*alpha2), (beta1 + 3.0*beta2)})
// C := mat.NewVecDense(2, nil)
// C.SolveVec(A, B)
// return x*x*x + C.AtVec(0)*x + C.AtVec(1)
// }}
res[0] = Funct{func(x float64) float64 {
A := mat.NewDense(2, 2, []float64{(-alpha1 - alpha2), alpha1, (beta1 + beta2), beta1})
B := mat.NewVecDense(2, []float64{(-alpha1 - 2.0*alpha2), (-beta1 - 2.0*beta2)})
C := mat.NewVecDense(2, nil)
C.SolveVec(A, B)
return x*x + C.AtVec(0)*x + C.AtVec(1)
return x*x + 2.0*x - 7.0
}}
res[1] = Funct{func(x float64) float64 {
A := mat.NewDense(2, 2, []float64{-alpha1, (alpha1 - alpha2), beta1, (beta1 + beta2)})
B := mat.NewVecDense(2, []float64{(alpha1 + 3.0*alpha2), (beta1 + 3.0*beta2)})
C := mat.NewVecDense(2, nil)
C.SolveVec(A, B)
return x*x*x + C.AtVec(0)*x + C.AtVec(1)
return x*x*x - 3.0*x + 2.0
}}

for i := 0; i < n-2; i++ {
res[i+2] = Funct{func(x float64) float64 {
return (1.0 - x*x) * (1.0 - x*x) * getP(2, i)(x)
Expand All @@ -69,17 +76,17 @@ func solveCollocation(p, r, f func(float64) float64, alpha1, alpha2, beta1, beta
frand := make([][]float64, 5)
ns := make([]int, 5)
ind := 0
for n := 4; n < 13; n += 2 {
ws := getWCol(n, alpha1, alpha2, beta1, beta2)
for n := 4; n < 14; n += 2 {
ws := getWCol(n+1, alpha1, alpha2, beta1, beta2)
//ws := getWs(n)
xch[ind] = getChebNodes(n)
c := getCCol(p, r, f, ws, xch[ind])
xch[ind] = makeNet(-1, 1, int(math.Pow(2.0, float64(n))))
c := getCCol(p, r, f, ws, getChebNodes(n))
res := getYn(n, *c, ws)
fch[ind] = make([]float64, n+1)
xrand[ind] = makeNet(-1, 1, n)
crand := getCCol(p, r, f, ws, xrand[ind])
fch[ind] = make([]float64, int(math.Pow(2.0, float64(n)))+1)
xrand[ind] = xch[ind]
crand := getCCol(p, r, f, ws, makeNet(-1, 1, n))
resrand := getYn(n, *crand, ws)
frand[ind] = make([]float64, n+1)
frand[ind] = make([]float64, int(math.Pow(2.0, float64(n)))+1)
// fmt.Println("\nCheba:")
for i, el := range xch[ind] {
fch[ind][i] = res.f(el)
Expand Down
8 changes: 4 additions & 4 deletions task7/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func main() {
if beta2*beta2 != 0 {
typeF = 2
}
a, b, eps, alpha, beta := -1.0, 1.0, 2e-4, 0.0, 0.0
x_d, net_d, _, n_d := solveTask(p8, q8, r8, f8, a, b, 2, eps, alpha1, alpha2, alpha, beta1, beta2, beta)
fmt.Println("Variant 10. Approximation results are in '8-nets.png'")
drowGraphic(x_d, net_d, n_d, "8-nets")
//a, b, eps, alpha, beta := -1.0, 1.0, 2e-4, 0.0, 0.0
//x_d, net_d, _, n_d := solveTask(p8, q8, r8, f8, a, b, 2, eps, alpha1, alpha2, alpha, beta1, beta2, beta)
//fmt.Println("Variant 10. Approximation results are in '8-nets.png'")
//drowGraphic(x_d, net_d, n_d, "8-nets")
fmt.Println("Вычисляем методом Ритца при разных n", typeF)
solveRitz(p8, r8, f8, typeF, alpha1, alpha2, beta1, beta2)
fmt.Println("Вычисляем методом коллокации при разных n")
Expand Down
6 changes: 3 additions & 3 deletions task7/ritz.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func getP(k, n int) func(x float64) float64 {
return p
} else if n == 1 {
p := func(x float64) float64 {
return float64(k+1) * x
return float64(k+1.0) * x
}
return p
}
p := func(x float64) float64 {
return float64((n+k+2)*(2*n+2*k+3))*x*getP(k, n-1)(x)/float64((n+2*k+2)*(n+2)) -
float64((n+k+2)*(n+k+1))*getP(k, n-2)(x)/float64((n+2*k+2)*(n+2))
return float64((n+k)*(2*n+2*k-1))*x*getP(k, n-1)(x)/float64((n+2*k)*(n)) -
float64((n+k)*(n+k-1))*getP(k, n-2)(x)/float64((n+2*k)*(n))
}
return p
}
Expand Down

0 comments on commit 6554e11

Please sign in to comment.