
Sub Macro()
Dim x As Double, y As Double, i As Integer
Dim AR(1 To 5) As Double, ARR(1 To 5) As Double
Dim n As Integer
a1 = 1
b1 = 4
c1 = 4
d1 = 1
e1 = 4
f1 = 4
AR(1) = x ^ 5 + x ^ 4 + x ^ 3 + x ^ 2 + x + 1
AR(2) = x2 ^ 5 + x2 ^ 4 + x2 ^ 3 + x2 ^ 2 + x2 + 1
AR(3) = x3 ^ 5 + x3 ^ 4 + x3 ^ 3 + x3 ^ 2 + x3 + 1
AR(4) = x4 ^ 5 + x4 ^ 4 + x4 ^ 3 + x4 ^ 2 + x4 + 1
AR(5) = x5 ^ 5 + x5 ^ 4 + x5 ^ 3 + x5 ^ 2 + x5 + 1
ARR(1) = a1 + b1 + c1 + d1 + e1 + f1
ARR(2) = a2 + b2 + c2 + d2 + e2 + f2
ARR(3) = a3 + b3 + c3 + d3 + e3 + f3
ARR(4) = a4 + b4 + c4 + d4 + e4 + f4
ARR(5) = a5 + b5 + c5 + d5 + e5 + f5
For i = 1 To n 'non parto da zero perchè il termine noto è diverso da zero
y = AR(1) * ARR(1)
Do while y<>0
.....................
Loop
Next i
End If |
Function f_x1(x As Single, a As Single, b As Single, c As Single, d As Single, e As Single, f As Single) As Single f_x1 = a * x ^ 5 + b * x ^ 4 + c * x ^ 3 + d * x ^ 2 + e * x + f End Function Sub macro() Dim y As Single a = 1 b = 4 c = 4 d = 1 e = 4 f = 4 For i = 1 To n Do ....... (trovare il valore di x che renda y=0) Loop Until y <> 0 Next Cells(1, 1) = x End Sub |
Function f_x1(x As Single, a As Single, b As Single, c As Single, d As Single, e As Single, f As Single) As Single
f_x1 = a * x ^ 5 + b * x ^ 4 + c * x ^ 3 + d * x ^ 2 + e * x + f
End Function
Sub macro()
Dim i as long, y As Single
For i = 1 To 1000000 'mi fermo a un milione di cicli per evitare un loop infinito
' assegna a y il valore della function definita sopra
y = f_x1(i, 1, 4, 4, 1, 4, 4)
' se y è zero esce dal ciclo
if y = 0 then exit for
Next
if y = 0 then
Cells(1, 1) = y
msgbox "Ho trovato uno zero"
else
cells(1, 1) = ""
msgbox "Non ho trovato uno zero nemmeno dopo un milione di cicli."
end if
End Sub |
ByVal x As Single
For i = -1000# To 1000#
If y = 0 Then
Cells(1, 1) = "y vale zero per x = " & i
MsgBox "Ho trovato uno zero"
Function f_x(ByVal x As Single, a As Single, b As Single, c As Single, d As Single, e As Single) As Single
f_x = a * x ^ 4 + b * x ^ 3 + c * x ^ 2 + d * x + e
End Function
Function f_v(ByVal v As Single, ByVal b1 As Single, ByVal c1 As Single, ByVal d1 As Single, ByVal e1 As Single) As Single
f_v = b1 * v ^ 3 + c1 * v ^ 2 + d1 * v + e1
End Function
Function f_w(ByVal w As Single, ByVal c2 As Single, ByVal d2 As Single, ByVal e2 As Single) As Single
f_w = c2 * w ^ 2 + d2 * w + e2
End Function
Sub Progetto_scomposizione()
Dim y As Single, d3 As Single, e3 As Single
b1 = a
c1 = b + x
d1 = c + (c1 * x)
e1 = d + (d1 * x)
c2 = b1
d2 = c1 + v
e2 = d1 + (d2 * v)
d3 = c2
e3 = d2 + w
For x = -10# To 10#
y = f_x(x, 1, 5, 5, -5, -6) ' assegna a y il valore della function definita sopra
If y = 0 Then Exit For ' se y è zero esce dal ciclo
Next
For v = -10# To 10#
y = f_v(v, b1, c1, d1, e1)
If y = 0 Then Exit For
Next
For w = -10# To 10#
y = f_w(w, c2, d2, e2)
If y = 0 Then Exit For
Next
Cells(1, 1) = "x°1"
Cells(2, 1) = x
Cells(3, 1) = "x°2"
Cells(4, 1) = v
Cells(5, 1) = "x°3"
Cells(6, 1) = w
Cells(7, 1) = "x°4"
Cells(8, 1) = (e3 / d3)
End Sub
|
Option Explicit
Function f_x(ByVal x As Single, a As Single, b As Single, c As Single, d As Single, e As Single) As Single
f_x = a * x ^ 4 + b * x ^ 3 + c * x ^ 2 + d * x + e
End Function
Function f_v(ByVal v As Single, ByVal b1 As Single, ByVal c1 As Single, ByVal d1 As Single, ByVal e1 As Single) As Single
f_v = b1 * v ^ 3 + c1 * v ^ 2 + d1 * v + e1
End Function
Function f_w(ByVal w As Single, ByVal c2 As Single, ByVal d2 As Single, ByVal e2 As Single) As Single
f_w = c2 * w ^ 2 + d2 * w + e2
End Function
Sub Progetto_scomposizione()
Dim a As Single, b As Single, c As Single, d As Single, e As Single
Dim y As Single, x As Single, w As Single, v As Single, z As Single
Dim b1 As Single, c1 As Single, d1 As Single, e1 As Single
Dim c2 As Single, d2 As Single, e2 As Single
Dim d3 As Single, e3 As Single
a = 1
b = 5
c = 5
d = -5
e = -6
For x = -10 To 10
y = f_x(x, a, b, c, d, e) ' assegna a y il valore della function definita sopra
If y = 0 Then Call mostra_soluzioni(x, v, w, e3, d3): Exit Sub
b1 = a
c1 = b + x
d1 = c + (c1 * x)
e1 = d + (d1 * x)
For v = -10 To 10
y = f_v(z, b1, c1, d1, e1)
If y = 0 Then Call mostra_soluzioni(x, v, w, e3, d3): Exit Sub
c2 = b1
d2 = c1 + v
e2 = d1 + (d2 * v)
For w = -10 To 10
y = f_w(w, c2, d2, e2)
d3 = c2
e3 = d2 + w
If y = 0 Then Call mostra_soluzioni(x, v, w, e3, d3): Exit Sub
Next w
Next v
Next x
End Sub
Private Sub mostra_soluzioni(x, v, w, e3, d3)
Cells(1, 1) = "x°1"
Cells(2, 1) = x
Cells(3, 1) = "x°2"
Cells(4, 1) = v
Cells(5, 1) = "x°3"
Cells(6, 1) = w
Cells(7, 1) = "x°4"
Cells(8, 1) = (e3 / d3)
End Sub
|
Private Sub mostra_soluzioni(x, v, w, e3, d3)
Cells(riga, "E") = "x°1 = "
Cells(riga, "F") = x
Cells(riga + 1, "E") = "x°2 ="
Cells(riga + 1, "F") = v
Cells(riga + 2, "E") = "x°3 ="
Cells(riga + 2, "F") = w
Cells(riga + 3, "E") = "x°4 ="
If d3 > 0 Then
Cells(riga + 3, "F") = (e3 / d3)
Else
Cells(riga + 3, "F") = "Divisione per zero"
End If
riga = riga + 5
Cells(1, "E").Select
End Sub |
