Hideki-San
07-06-2011, 18:33
Ciao ragazzi. Allora ho un problema.
Devo sviluppare un programma che disegni una funzione del tipo
f(x)= (ax^2+bx+c)/(a2x^2+b2x+c2)
Faccio così:
dc è una variabile che mi indica se il dominio della funziona sia qualunque x(dc=1) oppure se abbia dei punti di discontinuità(dc=0)
s è una variabili che contiene il valore della scala/zoom e può assumere il valore min di 10
xpoint e ypoint sono le coordinate dell'origine degli assi
If dc = 1 Then
xc = -50
y = ((a * xc ^ 2 + b * xc + c) / (a2 * xc ^ 2 + b2 * xc + c2)) * s
For i = xc To 50 Step 1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
End If
If dc = 0 Then
dom1 = dom * s
dom3 = dom2 * s
If dom1 > dom3 Then
temp = dom3
dom3 = dom1
dom1 = temp
End If
e.Graphics.DrawLine(Pens.Red, xpoint + dom1, 0, xpoint + dom1, 700)
e.Graphics.DrawLine(Pens.Red, xpoint + dom3, 0, xpoint + dom3, 700)
dom1 = (dom + 0.1) * s
dom3 = (dom2 + 0.1) * s
If dom1 > dom3 Then
temp = dom3
dom3 = dom1
dom1 = temp
End If
xc = 100
y = ((a * (xc) ^ 2 + b * (xc) + c) / (a2 * (xc) ^ 2 + b2 * (xc) + c2)) * s
For i = xc To dom3 Step -1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
xc = dom1
y = ((a * (xc) ^ 2 + b * (xc) + c) / (a2 * (xc) ^ 2 + b2 * (xc) + c2)) * s
For i = xc To -150 Step -1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
xc = dom1
y = ((a * (xc) ^ 2 + b * (xc) + c) / (a2 * (xc) ^ 2 + b2 * (xc) + c2)) * s
For i = xc To (dom3) Step 1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
End If
Ho alcuni problemi nel fatto che non funziona sempre xD cioè con alcuni valori che inserisco il disegno va, in altri mi da overflow. Poi vorrei sapere qual è il metodo per poter disegnare la funzione mettendo lo step del 'for' non intero tipo 0.1, perchè così il disegno mi viene incompleto e se metto meno di 1 il programma non funge.
Grz in anticipo
Devo sviluppare un programma che disegni una funzione del tipo
f(x)= (ax^2+bx+c)/(a2x^2+b2x+c2)
Faccio così:
dc è una variabile che mi indica se il dominio della funziona sia qualunque x(dc=1) oppure se abbia dei punti di discontinuità(dc=0)
s è una variabili che contiene il valore della scala/zoom e può assumere il valore min di 10
xpoint e ypoint sono le coordinate dell'origine degli assi
If dc = 1 Then
xc = -50
y = ((a * xc ^ 2 + b * xc + c) / (a2 * xc ^ 2 + b2 * xc + c2)) * s
For i = xc To 50 Step 1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
End If
If dc = 0 Then
dom1 = dom * s
dom3 = dom2 * s
If dom1 > dom3 Then
temp = dom3
dom3 = dom1
dom1 = temp
End If
e.Graphics.DrawLine(Pens.Red, xpoint + dom1, 0, xpoint + dom1, 700)
e.Graphics.DrawLine(Pens.Red, xpoint + dom3, 0, xpoint + dom3, 700)
dom1 = (dom + 0.1) * s
dom3 = (dom2 + 0.1) * s
If dom1 > dom3 Then
temp = dom3
dom3 = dom1
dom1 = temp
End If
xc = 100
y = ((a * (xc) ^ 2 + b * (xc) + c) / (a2 * (xc) ^ 2 + b2 * (xc) + c2)) * s
For i = xc To dom3 Step -1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
xc = dom1
y = ((a * (xc) ^ 2 + b * (xc) + c) / (a2 * (xc) ^ 2 + b2 * (xc) + c2)) * s
For i = xc To -150 Step -1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
xc = dom1
y = ((a * (xc) ^ 2 + b * (xc) + c) / (a2 * (xc) ^ 2 + b2 * (xc) + c2)) * s
For i = xc To (dom3) Step 1
y2 = ((a * i ^ 2 + b * i + c) / (a2 * i ^ 2 + b2 * i + c2)) * s
e.Graphics.DrawLine(Pens.Blue, xpoint + xc * s, ypoint - y, xpoint + i * s, ypoint - y2)
xc = i
y = y2
Next
End If
Ho alcuni problemi nel fatto che non funziona sempre xD cioè con alcuni valori che inserisco il disegno va, in altri mi da overflow. Poi vorrei sapere qual è il metodo per poter disegnare la funzione mettendo lo step del 'for' non intero tipo 0.1, perchè così il disegno mi viene incompleto e se metto meno di 1 il programma non funge.
Grz in anticipo