Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab3) #132

Open
wants to merge 3 commits into
base: Korchagin_Petr_Sergeevich
Choose a base branch
from
Open

lab3) #132

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions golang/internal/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package lab4

import (
"math"
)

func formula(x float64) float64 {
var a float64 = 1.2
var b float64 = 0.48
return ((math.Pow(b, 3) + math.Pow(math.Sin(a*x), 2)) / (math.Acos((x * b * x)) + math.Exp(-x/2)))
}

func TaskA(xN, xK, xD float64) ([]float64, []float64) {
x := []float64{}
y := []float64{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

используйте make длятого чтобы выделить нужный размер у массива для среза

for i := xN; i <= xK; i += xD {
y = append(y, formula(i))
x = append(x, i)
}
return x, y
}

func TaskB(xArray []float64) ([]float64, []float64) {
x := []float64{}
y := []float64{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут аналогично

for i := 0; i < len(xArray); i++ {
y = append(y, formula(xArray[i]))
x = append(x, xArray[i])
}
return x, y
}
20 changes: 19 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package main

import "fmt"
import (
"fmt"

"isuct.ru/informatics2022/internal/lab4"
)

func main() {
fmt.Println("Корчагин Пётр Сергеевич")
fmt.Println("Ответы на задачу A")
xN := 0.7
xK := 2.2
xD := 0.2
x, y := lab4.TaskA(xN, xK, xD)
for i := range y {
fmt.Println("x=", x[i], "y=", y[i])
}
fmt.Println("Ответы на задачу B")
xArray := []float64{0.25, 0.36, 0.56, 0.94, 1.28}
x, y = lab4.TaskB(xArray)
for i := range y {
fmt.Println("x=", x[i], "y=", y[i])
}
}