+ Reply to Thread
Results 1 to 2 of 2

Problem with sqrt

Hybrid View

  1. #1
    Registered User
    Join Date
    06-05-2016
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    4

    Problem with sqrt

    Hi!
    I have problem with sqrt.

    Code is:

    Option Explicit
    Dim X As Range
    Dim Y As Range
    Dim XT As Variant
    Dim XTX As Variant
    Dim odw As Variant
    Dim XTy As Variant
    Dim a As Variant
    Dim rowY As Long
    Dim rowX As Long
    Dim rowW As Long
    Dim i As Long
    Dim colY As Long
    Dim nazwa As Variant
    Dim colX As Long
    Dim yte As Variant
    Dim o As Variant
    Dim m As Long
    Dim ysr As Long
    Dim R2 As Long
    Dim war As Variant
    Dim Su As Variant
    
    Private Sub CommandButton1_Click()
        End
    End Sub
    
    Sub CommandButton2_Click()
    
        'pierwsze obliczenia
        
    Set X = Range(RefEdit1)
    Set Y = Range(RefEdit2)
    XT = Application.WorksheetFunction.Transpose(X)
    rowX = X.Rows.Count
    rowY = Y.Rows.Count
    colY = Y.Columns.Count
    colX = X.Columns.Count
        
        'warunki
        
    If colY > 1 Or colY < 1 Then
        MsgBox ("Liczba kolumn macierzy Y powinna wynosić 1")
    End If
    If rowX > rowY Or rowX < rowY Then
        MsgBox ("Liczba wierszy macierzy Y i X powinna być taka sama")
        End
    End If
    
        'parametry
        
        XTX = Application.WorksheetFunction.MMult(XT, X)
        odw = Application.WorksheetFunction.MInverse(XTX)
        XTy = Application.WorksheetFunction.MMult(XT, Y)
        a = Application.WorksheetFunction.MMult(odw, XTy)
        yte = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.MMult(Application.WorksheetFunction.Transpose(a), XT))
        ysr = Application.WorksheetFunction.Average(Y)
        
        'R2
        
        ReDim diff(1 To rowY, 1 To colY)
        
        For m = 1 To rowY
             diff(m, 1) = ((Y(m, 1) - yte(m, 1)) ^ 2)
        Next m
    
        ReDim diff2(1 To rowY, 1 To colY)
        
        For m = 1 To rowY
             diff2(m, 1) = (Y(m, 1) - ysr) ^ 2
        Next m
    
        o = Application.WorksheetFunction.Sum(diff) / Application.WorksheetFunction.Sum(diff2)
        R2 = 1 - o
        
        'Odchylenie
        
        war = Application.WorksheetFunction.Sum(diff) / (rowX - colX)
        Su = war^(1 / 2)
        
               'Wyniki
    
    Sheets.Add
    ActiveSheet.Name = "Wyniki KMNK"
    Range("A1").Value = "Parametry: "
    Range(Cells(2, 1), Cells(colX + 1, 1)).Select
    Selection.Value = a
    Range("C1").Value = "Y^"
    Range(Cells(2, 3), Cells(colY + 1, 3)).Select
    Selection.Value = yte
    Range("F1").Value = "R2: współczynnik determinacji"
    Range("H1").Value = R2
    Range("F2").Value = "Su: odchylenie standardowe"
    Range("H2").Value = Su
    End Sub
    Error: Type declaration character does not much declared data type.

    It is about war variable.

    Please help

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with sqrt

    Is war positive? What is war when that line is flagged?

    Maybe:

    war = Application.WorksheetFunction.Sum(diff) / Abs(rowX - colX)
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. =+g12*2.20452+10.518+(2*sqrt(10.9)-2*sqrt(g13))
    By luisfsantos in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-13-2013, 08:21 AM
  2. Excel 2007 : SQRT problems
    By frdranger25401 in forum Excel General
    Replies: 1
    Last Post: 04-14-2011, 01:56 PM
  3. UDF using SQRT function
    By Vlad999 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2007, 09:14 PM
  4. Unable to find values of SQRT(0)
    By big_ears in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-12-2006, 09:00 AM
  5. [SOLVED] find exact values of SQRT
    By big_ears in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2006, 03:00 AM
  6. We have SQRT. But what is the function for other roots - cubed ro.
    By ACC in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-02-2005, 04:06 PM
  7. how to multiply 29,5 with sqrt of 12
    By Smiley in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-10-2005, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1