<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
Sub Page_Load (sender As Object, e As EventArgs)
lbll.Text = "Calcolo della retta dei minimi quadrati "
End sub
Sub Submit(sender as object, e as EventArgs)
Dim valori(5,5) As double
Dim I, Sx, Sy, Sxy, Sx2, m, q, n As double
Dim y01, y02 As double
Dim objBitmap As New Bitmap(200,200)
Dim objGraphic As Graphics = Graphics.FromImage(objBitmap)
Dim whiteBrush As New SolidBrush(Color.White)
Dim redpen As New pen(Color.Red, 2)
Dim blackPen As New Pen(Color.Black, 2)
valori(1,1) = x1.text
valori(1,2) = y1.text
valori(2,1) = x2.text
valori(2,2) = y2.text
valori(3,1) = x3.text
valori(3,2) = y3.text
valori(4,1) = x4.text
valori(4,2) = y4.text
valori(5,1) = x5.text
valori(5,2) = y5.text
n = 5
sx = 0
sy = 0
sx2 = 0
sxy = 0
For I = 1 to 5
Valori(I,3) = valori(I,1) * valori(I,1)
Valori(I,4) = valori(I,1) * Valori(I,2)
Sx = sx + valori(I,1)
Sy = sy + valori(I,2)
Sx2 = sx2 + valori(I,3)
Sxy = sxy + valori(I,4)
Next I
m = (n*sxy-sx*sy)/(n*sx2-(sx)*(sx))
q = (sx2*sy-sxy*sx)/(n*sx^2-(sx)*(sx))
If q > 0 Then
lbl2.Text = "Risultato : Y=" & m & "X+" & q
Else
lbl2.Text = "Risultato : Y=" & m & "X" & q
End if
y01 = 195 - q
y02 = 195 - ((195*m)+q)
objGraphic.FillRectangle(whiteBrush, 0, 0, 200, 200)
objGraphic.DrawLine(blackPen, New Point(0,195), New Point(195,195))
objGraphic.DrawLine(blackPen, New Point(5,5), New Point(5,200))
objGraphic.DrawLine(redPen, New Point(5, y01), New Point(195, y02))
Response.ContentType = "image/gif"
objBitmap.Save (Response.OutputStream, ImageFormat.Gif)
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:label id="lbll" runat="server"
forecolor="#0000FF"
font-bold="true"/></p>
x1: <asp:TextBox id="x1" columns="10" runat="server" />
y1: <asp:TextBox id="y1" columns="10" runat="server" />
x2: <asp:TextBox id="x2" columns="10" runat="server" />
y2: <asp:TextBox id="y2" columns="10" runat="server" />
x3: <asp:TextBox id="x3" columns="10" runat="server" />
y3: <asp:TextBox id="y3" columns="10" runat="server" />
x4: <asp:TextBox id="x4" columns="10" runat="server" />
y4: <asp:TextBox id="y4" columns="10" runat="server" />
x5: <asp:TextBox id="x5" columns="10" runat="server" />
y5: <asp:TextBox id="y5" columns="10" runat="server" />
<asp:Button OnClick="Submit" Text="Esegui" runat="server" />
<asp:Label id="lbl2" runat="server" /></p>
</form>
</body>
</html>